package com.car.web.controller.index;

import java.io.*;
import java.net.URLEncoder;
import java.text.DateFormat;
import java.text.DateFormatSymbols;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.car.dal.dao.director.CenterDirectorDao;
import com.car.dal.dao.performance.LevleDao;
import com.car.dal.dao.performance.PerformanceInfoDao;
import com.car.dal.dao.quit.QuitDao;
import com.car.dal.object.*;

import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.car.dal.dao.category.TgCategoryDao;
import com.car.dal.dao.client.TgClientDao;
import com.car.dal.dao.grade.TgUsergradeDao;
import com.car.dal.dao.method.TgMethodDao;
import com.car.dal.dao.moneys.TgMoneyDao;
import com.car.dal.dao.office.TgOfficeDao;
import com.car.dal.dao.reception.TgReceptionDao;
import com.car.dal.dao.reserve.TgReserveDao;
import com.car.dal.dao.source.TgSourceDao;
import com.car.dal.dao.spread.JsSpreadDao;
import com.car.dal.dao.state.TgStateDao;
import com.car.dal.dao.sudent.StudentDao;
import com.car.dal.dao.teacher.TeacherDao;
import com.car.dal.dao.teaching.TeachingDao;
import com.car.dal.dao.tracking.TgTrackingDao;
import com.car.dal.dao.user.UserDao;
import com.car.dal.dao.user.UserinfoDao;
import com.car.dal.dao.user.UsernamesDao;
import com.car.dal.dao.vote.JsVoteDao;
import com.car.dal.dao.workload.TgworkloadDao;
import com.car.exception.BaseException;
import com.car.service.money.MoneyService;
import com.car.service.reception.ReceptionService;
import com.car.util.Constants;
import com.car.util.DateUtil;
import com.car.util.HtmlUtils;
import com.car.util.HttpUtil;
import com.car.util.JsonExecutor;
import com.car.util.JsonExecutor.JsonBiz;
import com.car.util.JsonValidator;
import com.car.util.MathUtil;
import com.car.util.Page;
import com.car.util.PageUtil;
import com.car.util.Result;
import com.car.util.ResultSupport;
import com.car.util.StringUtil;
import com.car.util.UserUtil;
import com.car.util.WebExecutor;
import com.car.util.WriterExcel;
import com.car.util.WebExecutor.Biz;
import com.car.web.controller.base.BaseController;
import com.car.web.controller.base.BaseVo;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.ssi.utils.SsiUtils;

/**
 * 登录控制
 *
 * @author Administrator
 */
@Controller
@RequestMapping("/index")
public class ConsuController extends BaseController {

	private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
	private static final Logger logger = Logger.getLogger(ConsuController.class);

	@Resource
	private UserinfoDao userinfoDao;
	@Resource
	private TgOfficeDao tgOfficeDao;
	@Resource
	private TgClientDao clientDao;
	@Resource
	private StudentDao studentDao;
	@Resource
	private TgSourceDao sourceDao;
	@Resource
	private TgCategoryDao categoryDao;
	@Resource
	private TgTrackingDao trackingDao;
	@Resource
	private TgStateDao stateDao;
	@Resource
	private TgReserveDao reserveDao;
	@Resource
	private JsSpreadDao spreadDao;
	@Resource
	private TgReceptionDao receptionDao;
	@Resource
	private JsVoteDao voteDao;
	@Resource
	private TgworkloadDao workloadDao;
	@Resource
	private TgUsergradeDao usergradeDao;
	@Resource
	private TgMethodDao methodDao;
	@Resource
	private PerformanceInfoDao performanceInfoDao;
	@Resource
	private CenterDirectorDao centerDirectorDao;
	@Resource
	private LevleDao levleDao;
	@Resource
	private UserDao userDao;
	@Resource
	private TgMoneyDao moneyDao;
	@Resource
	private ReceptionService receptionService;
	@Resource
	private MoneyService moneyService;
	@Resource
	private UsernamesDao usernamesDao;
	@Resource
	private QuitDao quitDao;
	@Resource
	private TeachingDao teachingDao;
	@Resource
	private TeacherDao teacherDao;
	private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

	// 进入首次咨询登记
	@RequestMapping(value = "/consultant_client_first")
	public ModelAndView work_view(ModelMap modelMap, final LoginVo loginVo, HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, loginVo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);

				List<TgSource> souList = sourceDao.getAll();
				List<TgCategory> cateList = categoryDao.findAll(TgCategory.class);

				result.setDefaultModel("souList", souList);
				result.setDefaultModel("cateList", cateList);
				return result;
			}
		});
		return new ModelAndView("consultant/consultant_client_first", modelMap);
	}

	// 查询联系方式
	@RequestMapping(value = "/query")
	public ModelAndView query(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String va = request.getParameter("va");
				String type = request.getParameter("type");

				TgUser user = UserUtil.getUserFromCookies();
				TgClient client = new TgClient();

				int cout = 0;
				if (type != null) {
					if (type.equals("phone")) {
						if (va != null && !"".equals(va)) {
							client.setPhone(va);
						}
					}
					if (type.equals("qq")) {
						if (va != null && !"".equals(va)) {
							client.setQq(va);
						}
					}
					if (type.equals("weixin")) {
						if (va != null && !"".equals(va)) {
							client.setWeixin(va);
						}
					}
					if (type.equals("email")) {
						if (va != null && !"".equals(va)) {
							client.setEmail(va);
						}
					}
					cout = clientDao.getClientQuery(client);
				}
				List<TgClient> list = null;
				if (cout > 0) {
					list = clientDao.getClientName(client);
				}
				if (list != null && list.size() > 0) {
					String name = list.get(0).getRawuser();
					result.setDefaultModel("user", user.getNickname());
					result.setDefaultModel("name", name);
				}
				result.setDefaultModel("type", type);
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	// 添加首次咨询登记
	@RequestMapping(value = "/addConsultant_client_first")
	public ModelAndView addConsultant_client_first(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				TgUser user = UserUtil.getUserFromCookies();
				// 客户资料
				String keyname = request.getParameter("keyname");
				String spcode = request.getParameter("spcode");
				String nickname = request.getParameter("nickname");
				String invalid = request.getParameter("invalid");
				String category = request.getParameter("category");
				String cdate = request.getParameter("start_date");
				String source = request.getParameter("source");
				String url = request.getParameter("url");
				String quests = request.getParameter("quests");
				String keyword = request.getParameter("keyword");
				String province = request.getParameter("province");
				String city = request.getParameter("city");
				String address = request.getParameter("address");
				String phone = request.getParameter("allPhone");
				String phone1 = request.getParameter("phone");
				String weixin = request.getParameter("weixin");
				String email = request.getParameter("email");
				String qq = request.getParameter("qq");
				String ip = request.getParameter("ip");
				String intention = request.getParameter("intention");
				String descs = request.getParameter("desc");
				// String phones = request.getParameter("phone");
				// 跟踪数据
				String states = request.getParameter("states");
				String remark = HtmlUtils.deleteAllHTMLTag(request.getParameter("remark"));
				String remind_date = request.getParameter("protime");
				String target = request.getParameter("target");
				/**
				 * 将数据添加到js_vote中
				 */

				// 学员数据
				String student = request.getParameter("student");

				TgUser u = UserUtil.getUserFromCookies();

				TgClient client = new TgClient();
				TgStudent students = null;
				TgTracking tracking = new TgTracking();
				if (keyname != null && !"".equals(keyname)) {
					client.setKeyname(keyname);
					List<TgClient> list = clientDao.findByExample(client);
					if (list != null && list.size() > 0) {
						client = list.get(0);
						if (nickname != null && !"".equals(nickname)) {
							client.setNickname(nickname);
						}
						if (invalid != null && !"".equals(invalid)) {
							client.setInvalid(Integer.parseInt(invalid));
						}
						if (client.getLodusername() != null && !"".equals(client.getLodusername())) {
							client.setUsername(u.getUsername());
							// 只有点击名字添加跟踪才会转客户资源列表
							if (source != null && !"".equals(source)) {
								client.setLodusername(" ");
							}

						}
						if (source != null && !"".equals(source)) {
							client.setSource(source);
						}
						if (weixin != null && !"".equals(weixin)) {
							client.setWeixin(weixin);
						}
						if (category != null && !"".equals(category)) {
							client.setCategory(category);
						}
						if (quests != null && !"".equals(quests)) {
							client.setQuests(quests);
						}

						if (phone != null && !"".equals(phone)) {
							if (phone.equals("[]")) {
								if (phone1 != null && !"".equals(phone1)) {
									client.setPhone(phone1);
								}
							} else {
								client.setPhone(phone);
							}
						}
						if (intention != null && !"".equals(intention)) {
							client.setIntention(intention);
						}

						if (descs != null && !"".equals(descs)) {
							if (StringUtil.getHanzi(descs)) {
								client.setDescs(descs);
							} else {
								client.setDescs("备注:" + descs);
							}
						}

						if (province != null && !"".equals(province)) {
							client.setProvince(province);
						}
						if (city != null && !"".equals(city)) {
							client.setCity(city);
						}
						if (qq != null && !"".equals(qq)) {
							client.setQq(qq);
						}
						if (spcode != null && !"".equals(spcode)) {
							client.setSpcode(spcode);
						}

						client.setMdate(new Date().getTime() / 1000);
						clientDao.update(client);
					}

					// 跟踪填写转交
					TgClient client1 = new TgClient();
					client1.setKeyname(keyname);
					List<TgClient> list1 = clientDao.findByExample(client1);
					if (list1 != null && list1.size() > 0) {
						client1 = list.get(0);
						if (target != null && !"".equals(target)) {
							client1.setLodusername(target);
							client1.setUsername(target);
							client1.setMdate(new Date().getTime() / 1000);
							clientDao.update(client1);

							if (client1.getType() != null && !"".equals(client1.getType())) {
								/* if(client1.getType()==1){ */
								JsVote vote = new JsVote();
								vote = voteDao.findById(JsVote.class, client1.getFrom_id());
								vote.setUsername(target);
								voteDao.update(vote);
								/* } */
								/*
								 * if(client1.getType()==2){ JsFromUser fromuser
								 * = new JsFromUser(); fromuser =
								 * fromuserDao.findById(JsFromUser.class,
								 * client1.getFrom_id());
								 * fromuser.setUsername(target);
								 * fromuserDao.update(fromuser); }
								 * if(client1.getType()==3){ TgClientImp
								 * clientImp = new TgClientImp(); clientImp =
								 * clientImpDao.findById(TgClientImp.class,
								 * client1.getFrom_id());
								 * clientImp.setTo_username(target);
								 * clientImpDao.update(clientImp); }
								 */
							}

						}
					}
					// 添加和更新跟踪记录
					TgTracking tra = new TgTracking();
					tra.setClient(keyname);
					List<TgTracking> tralist = trackingDao.findByExample(tra);
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
					Date now = new Date();
					try {
						String hehe = sdf.format(now);
						tra.setClient(keyname);
						if ((states != null && !"".equals(states)) || (remark != null && !"无".equals(remark))) {
							if (tralist != null && tralist.size() > 0) {
								String createTime = sdf.format(new Date(tralist.get(0).getCdate() * 1000));
								TgTracking tras = new TgTracking();
								tras = tralist.get(0);
								if (hehe.equals(createTime)) {
									tras.setKeyname(tralist.get(0).getKeyname());
									tras.setClient(keyname);
									tras.setId(tralist.get(0).getId());
									if (states != null && !"".equals(states)) {
										tras.setState(states);
									}
									if (remark != null && !"无".equals(remark)) {
										tras.setRemark(remark);
									}
									if (remind_date != null && !"".equals(remind_date)) {
										Date date = sdf.parse(remind_date);
										tras.setRemind_date(date.getTime() / 1000);
									}
									tras.setUsername(user.getUsername());
									tras.setMdate(new Date().getTime() / 1000);
									trackingDao.update(tras);
								} else {
									tra.setState(states);
									tra.setKeyname(SsiUtils.randomUUID());
									tra.setRemark(remark);
									if (remind_date != null && !"".equals(remind_date)) {
										Date date = sdf.parse(remind_date);
										tra.setRemind_date(date.getTime() / 1000);
									}
									tra.setUsername(user.getUsername());
									tra.setCdate(new Date().getTime() / 1000);
									tra.setMdate(new Date().getTime() / 1000);
									trackingDao.insert(tra);
								}
							} else {
								tra.setState(states);
								tra.setKeyname(SsiUtils.randomUUID());
								tra.setRemark(remark);
								if (remind_date != null && !"".equals(remind_date)) {
									Date date = sdf.parse(remind_date);
									tra.setRemind_date(date.getTime() / 1000);
								}
								tra.setUsername(user.getUsername());
								tra.setCdate(new Date().getTime() / 1000);
								tra.setMdate(new Date().getTime() / 1000);
								trackingDao.insert(tra);
							}
						}

					} catch (ParseException e) {
						e.printStackTrace();
					}

					if (student != null && !"".equals(student)) {
						try {
							JSONArray jsonArray = new JSONArray(student);
							if (jsonArray != null && jsonArray.length() > 0) {
								for (int i = 0; i < jsonArray.length(); i++) {
									students = new TgStudent();
									String id = jsonArray.getJSONObject(i).getString("id");
									students.setNickname(jsonArray.getJSONObject(i).getString("nickname"));
									students.setSex(jsonArray.getJSONObject(i).getString("sex"));
									String age = jsonArray.getJSONObject(i).getString("age");
									if (age != null && !"".equals(age)) {
										students.setAge(age);
									}
									String birthday = jsonArray.getJSONObject(i).getString("birthday");
									SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
									if (birthday != null && !"".equals(birthday)) {
										Date bir = sdf1.parse(birthday);
										students.setBirthday(bir.getTime() / 1000);
									}
									students.setSchool(jsonArray.getJSONObject(i).getString("school"));
									students.setFeature(jsonArray.getJSONObject(i).getString("feature"));
									students.setType(jsonArray.getJSONObject(i).getString("types"));
									String lesson = jsonArray.getJSONObject(i).getString("lesson");
									if (lesson != null && !"".equals(lesson)) {
										students.setLesson(Integer.parseInt(lesson));
									}
									students.setCard(jsonArray.getJSONObject(i).getString("card"));
									students.setSerial(jsonArray.getJSONObject(i).getString("serial"));
									students.setDeadline(jsonArray.getJSONObject(i).getString("deadline"));
									students.setMdate(new Date().getTime() / 1000);
									if (id != null && !"".equals(id)) {
										students.setId((long) Integer.parseInt(id));
										studentDao.update(students);
									} else {
										students.setPkey(keyname);
										students.setKeyname(SsiUtils.randomUUID());
										studentDao.insert(students);
									}
								}
							}

						} catch (Exception e) {
							e.printStackTrace();
						}
					}

				} else {
					if (nickname != null && !"".equals(nickname)) {
						client.setNickname(nickname);
					} else {
						client.setNickname("匿名");
					}
					if (invalid != null && !"".equals(invalid)) {
						client.setInvalid(Integer.parseInt(invalid));
					}
					client.setSource(source);
					client.setWeixin(weixin);
					client.setCategory(category);
					client.setQuests(quests);
					client.setSpcode(spcode);

					String keys = SsiUtils.randomUUID();
					client.setKeyname(keys);
					client.setUrl(url);
					client.setKeyword(keyword);

					client.setProvince(province);
					client.setCity(city);
					client.setAddress(address);
					client.setPhone(phone);
					client.setEmail(email);
					client.setQq(qq);
					client.setIp(ip);
					client.setRawusername(user.getUsername());
					client.setUsername(user.getUsername());
					client.setIntention(intention);
					if (StringUtil.getHanzi(descs)) {
						client.setDescs(descs);
					} else {
						client.setDescs("备注:" + descs);
					}
					client.setCdate(new Date().getTime() / 1000);
					client.setMdate(new Date().getTime() / 1000);
					clientDao.insert(client);

					if ((states != null && !"".equals(states)) || (remark != null && !"无".equals(remark))) {
						tracking.setKeyname(SsiUtils.randomUUID());
						tracking.setUsername(user.getUsername());
						tracking.setClient(keys);
						tracking.setState(states);
						tracking.setRemark(remark);
						tracking.setCdate(new Date().getTime() / 1000);
						tracking.setMdate(new Date().getTime() / 1000);

						if (remind_date != null && !"".equals(remind_date)) {
							SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
							try {
								Date date = sdf.parse(remind_date);
								tracking.setRemind_date(date.getTime() / 1000);
							} catch (ParseException e) {
								e.printStackTrace();
							}
						}
						trackingDao.insert(tracking);
					}
					try {
						JSONArray jsonArray = new JSONArray(student);
						if (jsonArray != null && jsonArray.length() > 0) {
							for (int i = 0; i < jsonArray.length(); i++) {
								students = new TgStudent();
								students.setKeyname(SsiUtils.randomUUID());
								students.setPkey(keys);
								students.setNickname(jsonArray.getJSONObject(i).getString("nickname"));
								students.setSex(jsonArray.getJSONObject(i).getString("sex"));
								String age = jsonArray.getJSONObject(i).getString("age");
								if (age != null && !"".equals(age)) {
									students.setAge(age);
								}
								String birthday = jsonArray.getJSONObject(i).getString("birthday");
								SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
								if (birthday != null && !"".equals(birthday)) {
									Date bir = sdf.parse(birthday);
									students.setBirthday(bir.getTime() / 1000);
								}
								students.setSchool(jsonArray.getJSONObject(i).getString("school"));
								students.setFeature(jsonArray.getJSONObject(i).getString("feature"));
								students.setType(jsonArray.getJSONObject(i).getString("types"));
								students.setType(jsonArray.getJSONObject(i).getString("types"));
								String lesson = jsonArray.getJSONObject(i).getString("lesson");
								if (lesson != null && !"".equals(lesson)) {
									students.setLesson(Integer.parseInt(lesson));
								}
								students.setCard(jsonArray.getJSONObject(i).getString("card"));
								students.setSerial(jsonArray.getJSONObject(i).getString("serial"));
								students.setDeadline(jsonArray.getJSONObject(i).getString("deadline"));
								students.setMdate(new Date().getTime() / 1000);
								studentDao.insert(students);
							}
						}
						JsVote jsVote = new JsVote();
						List<JsVote> votelist = null;
						int ask_cn = 0;
						if (phone1 != null && phone1 != "") {
							jsVote.setPhone(phone1);
							votelist = voteDao.findByExample(jsVote);
							if (votelist != null && votelist.size() > 0) {
								ask_cn = votelist.size();
							}
						}
						jsVote.setSourceTable(3);
						jsVote.setCdate(new Date().getTime() / 1000);
						jsVote.setKeyname(keys + "");
						jsVote.setSpcode(spcode + "");
						// jsVote.setNickname(nickname+"");
						jsVote.setSource(source + "");
						jsVote.setUrl(url + "");
						jsVote.setKeyword(keyword + "");
						jsVote.setProvince(province + "");
						jsVote.setCity(city + "");
						jsVote.setAddress(address + "");
						jsVote.setAsk_cn(ask_cn);
						// jsVote.setPhone(phone1+"");
						jsVote.setWeixin(weixin + "");
						jsVote.setEmail(email + "");
						jsVote.setQq(qq + "");
						jsVote.setIp(ip + "");
						jsVote.setUsername(user.getUsername());
						jsVote.setLianxiName(nickname);
						jsVote.setTo_username(user.getUsername());
						// jsVote.setDesc(descs+"");
						voteDao.insert(jsVote);

					} catch (Exception e) {
						e.printStackTrace();
					}

				}
				return result;
			}
		});

		return new ModelAndView("", modelMap);
	}

	// 客户资源列表
	@RequestMapping(value = "/consultant_client_list")
	public ModelAndView consultant_client_list(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, vo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String nickname = request.getParameter("nickname");
				String invalid = request.getParameter("btnInvalid");// 有效和无效
				String isBySigned = request.getParameter("isBySigned");// 根据更新时间排序
				String startTime = request.getParameter("startTime");
				String endTime = request.getParameter("endTime");
				String intention = request.getParameter("intention");
				String state1 = request.getParameter("state");
				String sname = request.getParameter("sname");
				String state_s = request.getParameter("state_s");

				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				TgUser user = UserUtil.getUserFromCookies();

				TgClient client = new TgClient();
				client.setUsername(user.getUsername());
				if (nickname != null && !"".equals(nickname) && !"null".equals(nickname)) {
					client.setNickname(nickname);
					result.setDefaultModel("nickname", nickname);
				}
				if (invalid != null && !"".equals(invalid) && !"null".equals(invalid) && !"false".equals(invalid)) {
					client.setInvalid(0);
				}
				if (startTime != null && !"".equals(startTime) && !"null".equals(startTime)) {
					try {
						Date date = sdf.parse(startTime);
						client.setStartTime(date.getTime() / 1000);
					} catch (ParseException e) {
						e.printStackTrace();
					}
				}
				if (endTime != null && !"".equals(endTime) && !"null".equals(endTime)) {
					try {
						Date date = sdf.parse(endTime);
						client.setEndTime(date.getTime() / 1000);
					} catch (ParseException e) {
						e.printStackTrace();
					}
				}
				if (sname != null && sname.equals("1")) {
					client.setUsername("");
					client.setSname("市场部问卷,市场部推广,公益讲座,传单派发");
				}
				// 判断客户状态
				if ((state1 != null && !"".equals(state1) || (state_s != null && !"".equals(state_s)))) {
					if ((state1.equals("已预约")) || state_s.equals("已预约")) {
						client.setRenum(2);
						client.setRemin(1);
					} else if (state1.equals("未出现") || state_s.equals("未出现")) {
						client.setRenum(3);
						client.setRemin(3);
					} else if (state1.equals("已缴费") || state_s.equals("已缴费")) {
						client.setRecenum(6);
						client.setRecemin(6);
					} else if (state1.equals("已测评") || state_s.equals("已测评")) {
						client.setRecenum(5);
						client.setRecemin(1);
					} else if (state1.equals("无") || state_s.equals("无")) {
						client.setRenum_n(0);

					}
				}

				if (intention != null && !"".equals(intention) && !"null".equals(intention)) {
					client.setIntention(intention);
					result.setDefaultModel("intention", intention);
				}

				Integer currPage = 1;
				if (vo.getCurrPage() != null && !"".equals(vo.getCurrPage())) {
					currPage = vo.getCurrPage();
				}

				Integer total = clientDao.getClientCount(client);

				Page page = PageUtil.createPage(8, currPage, total);
				List<TgClient> list = new ArrayList<TgClient>();
				if (isBySigned != null && isBySigned.equals("cdate")) {
					// 根据创建时间排序
					list = clientDao.getClientByTypeCdate(client, page);
				} else {
					// 根据更新时间排序
					list = clientDao.getTgClientByType(client, page);
				}
				try {

					TgStudent student = new TgStudent();

					if (list != null && list.size() > 0) {
						Gson gson = new Gson();
						for (TgClient c : list) {
							// 时间和备注内容
							if (c.getMdate() != null && !"".equals(c.getMdate())) {
								String date = sdf2.format(new Date(c.getMdate() * 1000));
								c.setModeTime(date);
							}

							if (c.getCdate() != null && !"".equals(c.getCdate())) {
								String date = sdf2.format(new Date(c.getCdate() * 1000));
								c.setDateTime(date);
							}

							if (c.getPhone() != null && !"".equals(c.getPhone())) {
								if (c.getPhone().contains("[{")) {
									List<Phone> phone = gson.fromJson(c.getPhone(), new TypeToken<List<Phone>>() {
									}.getType());
									c.setPhlist(phone);
									// c.setPhone(c.getPhlist().get(0).getPhone());
								}
							}
							// 学生
							if (c.getKeyname() != null && !"".equals(c.getKeyname())) {
								student.setPkey(c.getKeyname());
								List<TgStudent> studentList = studentDao.getAgeFeature(student);
								if (studentList != null && studentList.size() > 0) {
									String stu = "";
									String context = "";

									for (int i = 0; i < studentList.size(); i++) {
										String age = studentList.get(i).getAge();
										if (age == null) {
											age = "0";
										}
										stu += studentList.get(i).getNickname() + "<span class=\"caption\">(" + age
												+ "岁" + ")</span>,";

										String con = "";
										String Contentq = "";
										if (studentList.get(i).getFeature() != null
												&& !"".equals(studentList.get(i).getFeature())) {
											studentList.get(i).setFeature(
													studentList.get(i).getFeature().replace("&nbsp;", "").trim());
											boolean flag1 = StringUtil.getHanzi(studentList.get(i).getFeature());
											if (!flag1) {
												byte[] bytes = StringUtil.hexDecode(studentList.get(i).getFeature());
												Contentq += new String(bytes, "UTF-8");
												if (Contentq != null && !"".equals(Contentq)) {
													con = studentList.get(i).getNickname() + ":(" + Contentq + ")";
												}
											} else {
												if (studentList.get(i).getFeature() != null
														&& !"".equals(studentList.get(i).getFeature())) {
													con = studentList.get(i).getNickname() + ":("
															+ studentList.get(i).getFeature() + ")";
												}
											}
											if (con != null && !"".equals(con)) {
												context = context + con + "</br>";
												if (context.contains("\"")) {
													context = context.replace('"', ' ');
												}
											}
										}
										c.setFeature(context);
									}
									c.setStudent(stu);
								}
							}
							// 客户状态
							String stat = "";
							if (c.getState() != null && !"".equals(c.getState())) {
								int renum = c.getState();
								if (renum >= 1 && renum <= 2) {
									stat = "已预约";
								} else if (renum == 3) {
									stat = "未出现";
								}
								c.setStates(stat);
							}

							if (c.getWorth() != null && !"".equals(c.getWorth())) {
								Integer recenum = c.getWorth();
								if (recenum == 6) {
									if (stat != "") {
										stat = stat + "," + "已缴费";
									} else {
										stat = "已缴费";
									}
								} else if (0 < recenum && recenum <= 5) {
									if (stat != "") {
										stat = stat + "," + "已测评";
									} else {
										stat = "已测评";
									}
								}
								c.setStates(stat);
							}

							// 最后更新信息和状态和总更新数量
							if (c.getLastdate() != null && !"".equals(c.getLastdate())) {
								String createTime = sdf2.format(new Date(c.getLastdate() * 1000));
								c.setNewTime(createTime);
							}

							if (c.getLast_track() != null && !"".equals(c.getLast_track())) {
								c.setLast_track(c.getLast_track().replace("&nbsp;", "").trim());
								if (StringUtil.isNum(c.getLast_track())) {
									c.setFallow(c.getLast_track());
								} else {
									boolean flag = StringUtil.getHanzi(c.getLast_track().replaceAll("</?[^<]+>", ""));
									if (!flag) {
										byte[] bytes = StringUtil.hexDecode(c.getLast_track());
										String ObjContent = new String(bytes, "UTF-8");
										c.setFallow(ObjContent);
									} else {
										c.setFallow(c.getLast_track());
									}
								}
								if (c.getFallow().contains("\"")) {
									c.setFallow(c.getFallow().replace('"', ' '));
								}
							}

							if (c.getTrackings() != null && !"".equals(c.getTrackings())) {
								c.setTracksize(String.valueOf(c.getTrackings()));
							}
						}
					}
				} catch (Exception e) {
					e.printStackTrace();
				}

				TgUserinfo userinfo = new TgUserinfo();
				userinfo.setJob("课程顾问");
				List<TgUserinfo> uList = userinfoDao.getUserInfoByUserInfo(userinfo);

				userinfo.setJob("在线课程顾问");
				List<TgUserinfo> uLists = userinfoDao.getUserInfoByUserInfo(userinfo);

				List<TgState> stateList = stateDao.findAll(TgState.class);
				result.setDefaultModel("stateList", stateList);

				result.setDefaultModel("invalid", invalid);
				result.setDefaultModel("isBySigned", isBySigned);
				result.setDefaultModel("startTime", startTime);
				result.setDefaultModel("endTime", endTime);
				result.setDefaultModel("page", page);
				result.setDefaultModel("state1", state1);
				result.setDefaultModel("list", list);
				result.setDefaultModel("uList", uList);
				result.setDefaultModel("uLists", uLists);
				result.setDefaultModel("state_s", state_s);
				result.setDefaultModel("sname", sname);
				return result;
			}
		});
		return new ModelAndView("consultant/consultant_client_list", modelMap);
	}

	// 新转客户列表
	@RequestMapping(value = "/consultant_client_list2")
	public ModelAndView consultant_client_list2(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, vo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String nickname = request.getParameter("nickname");
				String invalid = request.getParameter("btnInvalid");// 有效和无效
				String isBySigned = request.getParameter("isBySigned");// 根据更新时间排序
				String startTime = request.getParameter("startTime");
				String endTime = request.getParameter("endTime");
				String intention = request.getParameter("intention");// 意向度
				String state1 = request.getParameter("state");
				String state_s = request.getParameter("state_s");
				String lphone = request.getParameter("phone");
				String qq = request.getParameter("QQ");
				String weixin = request.getParameter("weixin");
				String province = request.getParameter("province");
				String city = request.getParameter("city");

				TgUser user = UserUtil.getUserFromCookies();
				TgClient client = new TgClient();
				client.setLodusername(user.getUsername());
				if (nickname != null && !"".equals(nickname) && !"null".equals(nickname)) {

					client.setNickname(nickname);
					result.setDefaultModel("nickname", nickname);
				}

				if (invalid != null && !"".equals(invalid) && !"null".equals(invalid) && !"false".equals(invalid)) {
					client.setInvalid(0);
				}
				if (startTime != null && !"".equals(startTime) && !"null".equals(startTime)) {
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
					try {
						Date date = sdf.parse(startTime);
						client.setStartTime(date.getTime() / 1000);
					} catch (ParseException e) {
						e.printStackTrace();
					}
				}
				if (endTime != null && !"".equals(endTime) && !"null".equals(endTime)) {
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
					try {
						Date date = sdf.parse(endTime);
						client.setStartTime(date.getTime() / 1000);
					} catch (ParseException e) {
						e.printStackTrace();
					}
				}

				// 判断客户状态
				if ((state1 != null && !"".equals(state1) || (state_s != null && !"".equals(state_s)))) {
					if ((state1.equals("已预约")) || state_s.equals("已预约")) {
						client.setRenum(2);
						client.setRemin(1);
					} else if (state1.equals("未出现") || state_s.equals("未出现")) {
						client.setRenum(3);
						client.setRemin(3);
					} else if (state1.equals("已缴费") || state_s.equals("已缴费")) {
						client.setRecenum(6);
						client.setRecemin(6);
					} else if (state1.equals("已测评") || state_s.equals("已测评")) {
						client.setRecenum(5);
						client.setRecemin(1);
					}
				}

				if (intention != null && !"".equals(intention) && !"null".equals(intention)) {
					client.setIntention(intention);
					result.setDefaultModel("intention", intention);
				}
				if (lphone != null && !"".equals(lphone) && !"null".equals(lphone)) {
					client.setPhone(lphone);
					result.setDefaultModel("phone", lphone);
				}
				if (weixin != null && !"".equals(weixin) && !"null".equals(weixin)) {
					client.setWeixin(weixin);
					result.setDefaultModel("weixin", weixin);
				}
				if (qq != null && !"".equals(qq) && !"null".equals(qq)) {
					client.setQq(qq);
					result.setDefaultModel("qq", qq);
				}
				if (province != null && !"".equals(province) && !"null".equals(province)) {
					client.setProvince(province);
					result.setDefaultModel("province", province);
				}
				if (city != null && !"".equals(city) && !"null".equals(city)) {
					client.setCity(city);
					result.setDefaultModel("city", city);
				}

				Integer currPage = 1;
				if (vo.getCurrPage() != null && !"".equals(vo.getCurrPage())) {
					currPage = vo.getCurrPage();
				}

				Integer total = clientDao.getClientCount2(client);

				Page page = PageUtil.createPage(8, currPage, total);
				List<TgClient> list = new ArrayList<TgClient>();
				if (isBySigned != null && isBySigned.equals("cdate")) {
					// 根据创建时间排序
					list = clientDao.getClientByTypeCdate2(client, page);
				} else {
					// 根据更新时间排序
					list = clientDao.getTgClientByType2(client, page);
				}
				try {
					TgStudent student = new TgStudent();
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					if (list != null && list.size() > 0) {
						for (TgClient c : list) {
							// 时间和备注内容
							if (c.getMdate() != null && !"".equals(c.getMdate())) {
								String date = sdf.format(new Date(c.getMdate() * 1000));
								c.setModeTime(date);
							}

							if (c.getCdate() != null && !"".equals(c.getCdate())) {
								String date = sdf.format(new Date(c.getCdate() * 1000));
								c.setDateTime(date);
							}

							if (c.getDescs() != null && !"".equals(c.getDescs())) {
								if (StringUtil.isNum(c.getDescs())) {
									c.setDescs(c.getDescs());
								}
								boolean flag = StringUtil.getHanzi(c.getDescs());
								if (!flag) {
									byte[] bytes = StringUtil.hexDecode(c.getDescs());
									String ObjContent = new String(bytes, "UTF-8");
									c.setDescs(ObjContent);
								}
							}

							if (c.getPhone() != null && !"".equals(c.getPhone())) {
								Gson gson = new Gson();// new一个Gson对象
								if (c.getPhone().contains("[{")) {
									List<Phone> phone = gson.fromJson(c.getPhone(), new TypeToken<List<Phone>>() {
									}.getType());
									c.setPhlist(phone);
									// c.setPhone(c.getPhlist().get(0).getPhone());
								}
							}
							// 学生
							if (c.getKeyname() != null && !"".equals(c.getKeyname())) {
								student.setPkey(c.getKeyname());
								List<TgStudent> studentList = studentDao.getAgeFeature(student);
								if (studentList != null && studentList.size() > 0) {
									String stu = "";
									String context = "";

									for (int i = 0; i < studentList.size(); i++) {
										String age = studentList.get(i).getAge();
										if (age == null) {
											age = "0";
										}
										stu += studentList.get(i).getNickname() + "<span class=\"caption\">(" + age
												+ "岁" + ")</span>,";

										String con = "";
										String Contentq = "";
										if (studentList.get(i).getFeature() != null
												&& !"".equals(studentList.get(i).getFeature())) {
											boolean flag1 = StringUtil.getHanzi(studentList.get(i).getFeature());
											if (!flag1) {
												byte[] bytes = StringUtil.hexDecode(studentList.get(i).getFeature());
												Contentq += new String(bytes, "UTF-8");
												if (Contentq != null && !"".equals(Contentq)) {
													con = studentList.get(i).getNickname() + ":(" + Contentq + ")";
												}
											} else {
												if (studentList.get(i).getFeature() != null
														&& !"".equals(studentList.get(i).getFeature())) {
													con = studentList.get(i).getNickname() + ":("
															+ studentList.get(i).getFeature() + ")";
												}
											}
											if (con != null && !"".equals(con)) {
												context = context + con + "</br>";
												if (context.contains("\"")) {
													context = context.replace('"', ' ');
												}
											}
										}
										c.setFeature(context);
									}
									c.setStudent(stu);
								}
							}
							// 客户状态
							String stat = "";
							if (c.getState() != null && !"".equals(c.getState())) {
								int renum = c.getState();
								if (renum >= 1 && renum <= 2) {
									stat = "已预约";
								} else if (renum == 3) {
									stat = "未出现";
								}
								c.setStates(stat);
							}

							if (c.getWorth() != null && !"".equals(c.getWorth())) {
								Integer recenum = c.getWorth();
								if (recenum == 6) {
									if (stat != "") {
										stat = stat + "," + "已缴费";
									} else {
										stat = "已缴费";
									}
								} else if (0 < recenum && recenum <= 5) {
									if (stat != "") {
										stat = stat + "," + "已测评";
									} else {
										stat = "已测评";
									}
								}
								c.setStates(stat);
							}

							// 最后更新信息和状态和总更新数量
							if (c.getLastdate() != null && !"".equals(c.getLastdate())) {
								String createTime = sdf.format(new Date(c.getLastdate() * 1000));
								c.setNewTime(createTime);
							}

							if (c.getLast_track() != null && !"".equals(c.getLast_track())) {
								c.setLast_track(c.getLast_track().replace("&nbsp;", "").trim());
								if (StringUtil.isNum(c.getLast_track())) {
									c.setFallow(c.getLast_track());
								} else {
									boolean flag = StringUtil.getHanzi(c.getLast_track());
									if (!flag) {
										byte[] bytes = StringUtil.hexDecode(c.getLast_track());
										String ObjContent = new String(bytes, "UTF-8");
										c.setFallow(ObjContent);
									} else {
										c.setFallow(c.getLast_track());
									}
								}
							}
							if (c.getTrackings() != null && !"".equals(c.getTrackings())) {
								c.setTracksize(String.valueOf(c.getTrackings()));
							}

						}
					}
				} catch (Exception e) {
					e.printStackTrace();
				}

				TgUserinfo userinfo = new TgUserinfo();
				userinfo.setJob("课程顾问");
				List<TgUserinfo> uList = userinfoDao.getUserInfoByUserInfo(userinfo);

				TgUserinfo userinfo1 = new TgUserinfo();
				userinfo1.setJob("在线课程顾问");
				List<TgUserinfo> uLists = userinfoDao.getUserInfoByUserInfo(userinfo1);

				List<TgState> stateList = stateDao.findAll(TgState.class);// 查询出所以的客户状态.
				result.setDefaultModel("stateList", stateList);

				result.setDefaultModel("invalid", invalid);
				result.setDefaultModel("isBySigned", isBySigned);
				result.setDefaultModel("startTime", startTime);
				result.setDefaultModel("endTime", endTime);
				result.setDefaultModel("page", page);
				result.setDefaultModel("state1", state1);
				result.setDefaultModel("list", list);
				result.setDefaultModel("uList", uList);
				result.setDefaultModel("uLists", uLists);
				result.setDefaultModel("state_s", state_s);
				return result;
			}
		});
		return new ModelAndView("consultant/consultant_client_list2", modelMap);
	}

	// 市场部新转客户列表
	@RequestMapping(value = "/consultant_client_list3")
	public ModelAndView consultant_client_list3(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, vo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String nickname = request.getParameter("nickname");
				String invalid = request.getParameter("btnInvalid");// 有效和无效
				String isBySigned = request.getParameter("isBySigned");// 根据更新时间排序
				String startTime = request.getParameter("startTime");
				String endTime = request.getParameter("endTime");
				String intention = request.getParameter("intention");// 意向度
				String state1 = request.getParameter("state");
				String state_s = request.getParameter("state_s");
				String lphone = request.getParameter("phone");
				String qq = request.getParameter("QQ");
				String weixin = request.getParameter("weixin");
				String province = request.getParameter("province");
				String city = request.getParameter("city");

				TgUser user = UserUtil.getUserFromCookies();
				TgClient client = new TgClient();
				client.setLodusername(user.getUsername());
				if (nickname != null && !"".equals(nickname) && !"null".equals(nickname)) {

					client.setNickname(nickname);
					result.setDefaultModel("nickname", nickname);
				}

				if (invalid != null && !"".equals(invalid) && !"null".equals(invalid) && !"false".equals(invalid)) {
					client.setInvalid(0);
				}
				if (startTime != null && !"".equals(startTime) && !"null".equals(startTime)) {
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
					try {
						Date date = sdf.parse(startTime);
						client.setStartTime(date.getTime() / 1000);
					} catch (ParseException e) {
						e.printStackTrace();
					}
				}
				if (endTime != null && !"".equals(endTime) && !"null".equals(endTime)) {
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
					try {
						Date date = sdf.parse(endTime);
						client.setStartTime(date.getTime() / 1000);
					} catch (ParseException e) {
						e.printStackTrace();
					}
				}

				// 判断客户状态
				if ((state1 != null && !"".equals(state1) || (state_s != null && !"".equals(state_s)))) {
					if ((state1.equals("已预约")) || state_s.equals("已预约")) {
						client.setRenum(2);
						client.setRemin(1);
					} else if (state1.equals("未出现") || state_s.equals("未出现")) {
						client.setRenum(3);
						client.setRemin(3);
					} else if (state1.equals("已缴费") || state_s.equals("已缴费")) {
						client.setRecenum(6);
						client.setRecemin(6);
					} else if (state1.equals("已测评") || state_s.equals("已测评")) {
						client.setRecenum(5);
						client.setRecemin(1);
					}
				}

				if (intention != null && !"".equals(intention) && !"null".equals(intention)) {
					client.setIntention(intention);
					result.setDefaultModel("intention", intention);
				}
				if (lphone != null && !"".equals(lphone) && !"null".equals(lphone)) {
					client.setPhone(lphone);
					result.setDefaultModel("phone", lphone);
				}
				if (weixin != null && !"".equals(weixin) && !"null".equals(weixin)) {
					client.setWeixin(weixin);
					result.setDefaultModel("weixin", weixin);
				}
				if (qq != null && !"".equals(qq) && !"null".equals(qq)) {
					client.setQq(qq);
					result.setDefaultModel("qq", qq);
				}
				if (province != null && !"".equals(province) && !"null".equals(province)) {
					client.setProvince(province);
					result.setDefaultModel("province", province);
				}
				if (city != null && !"".equals(city) && !"null".equals(city)) {
					client.setCity(city);
					result.setDefaultModel("city", city);
				}

				Integer currPage = 1;
				if (vo.getCurrPage() != null && !"".equals(vo.getCurrPage())) {
					currPage = vo.getCurrPage();
				}

				Integer total = clientDao.getClientCount3(client);

				Page page = PageUtil.createPage(8, currPage, total);
				List<TgClient> list = new ArrayList<TgClient>();
				if (isBySigned != null && isBySigned.equals("cdate")) {
					// 根据创建时间排序
					list = clientDao.getClientByTypeCdate3(client, page);
				} else {
					// 根据更新时间排序
					list = clientDao.getTgClientByType3(client, page);
				}
				try {
					TgStudent student = new TgStudent();
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					if (list != null && list.size() > 0) {
						for (TgClient c : list) {
							// 时间和备注内容
							if (c.getMdate() != null && !"".equals(c.getMdate())) {
								String date = sdf.format(new Date(c.getMdate() * 1000));
								c.setModeTime(date);
							}

							if (c.getCdate() != null && !"".equals(c.getCdate())) {
								String date = sdf.format(new Date(c.getCdate() * 1000));
								c.setDateTime(date);
							}

							if (c.getDescs() != null && !"".equals(c.getDescs())) {
								if (StringUtil.isNum(c.getDescs())) {
									c.setDescs(c.getDescs());
								}
								boolean flag = StringUtil.getHanzi(c.getDescs());
								if (!flag) {
									byte[] bytes = StringUtil.hexDecode(c.getDescs());
									String ObjContent = new String(bytes, "UTF-8");
									c.setDescs(ObjContent);
								}
							}

							if (c.getPhone() != null && !"".equals(c.getPhone())) {
								Gson gson = new Gson();// new一个Gson对象
								if (c.getPhone().contains("[{")) {
									List<Phone> phone = gson.fromJson(c.getPhone(), new TypeToken<List<Phone>>() {
									}.getType());
									c.setPhlist(phone);
									// c.setPhone(c.getPhlist().get(0).getPhone());
								}
							}
							// 学生
							if (c.getKeyname() != null && !"".equals(c.getKeyname())) {
								student.setPkey(c.getKeyname());
								List<TgStudent> studentList = studentDao.getAgeFeature(student);
								if (studentList != null && studentList.size() > 0) {
									String stu = "";
									String context = "";

									for (int i = 0; i < studentList.size(); i++) {
										String age = studentList.get(i).getAge();
										if (age == null) {
											age = "0";
										}
										stu += studentList.get(i).getNickname() + "<span class=\"caption\">(" + age
												+ "岁" + ")</span>,";

										String con = "";
										String Contentq = "";
										if (studentList.get(i).getFeature() != null
												&& !"".equals(studentList.get(i).getFeature())) {
											boolean flag1 = StringUtil.getHanzi(studentList.get(i).getFeature());
											if (!flag1) {
												byte[] bytes = StringUtil.hexDecode(studentList.get(i).getFeature());
												Contentq += new String(bytes, "UTF-8");
												if (Contentq != null && !"".equals(Contentq)) {
													con = studentList.get(i).getNickname() + ":(" + Contentq + ")";
												}
											} else {
												if (studentList.get(i).getFeature() != null
														&& !"".equals(studentList.get(i).getFeature())) {
													con = studentList.get(i).getNickname() + ":("
															+ studentList.get(i).getFeature() + ")";
												}
											}
											if (con != null && !"".equals(con)) {
												context = context + con + "</br>";
												if (context.contains("\"")) {
													context = context.replace('"', ' ');
												}
											}
										}
										c.setFeature(context);
									}
									c.setStudent(stu);
								}
							}
							// 客户状态
							String stat = "";
							if (c.getState() != null && !"".equals(c.getState())) {
								int renum = c.getState();
								if (renum >= 1 && renum <= 2) {
									stat = "已预约";
								} else if (renum == 3) {
									stat = "未出现";
								}
								c.setStates(stat);
							}

							if (c.getWorth() != null && !"".equals(c.getWorth())) {
								Integer recenum = c.getWorth();
								if (recenum == 6) {
									if (stat != "") {
										stat = stat + "," + "已缴费";
									} else {
										stat = "已缴费";
									}
								} else if (0 < recenum && recenum <= 5) {
									if (stat != "") {
										stat = stat + "," + "已测评";
									} else {
										stat = "已测评";
									}
								}
								c.setStates(stat);
							}

							// 最后更新信息和状态和总更新数量
							if (c.getLastdate() != null && !"".equals(c.getLastdate())) {
								String createTime = sdf.format(new Date(c.getLastdate() * 1000));
								c.setNewTime(createTime);
							}

							if (c.getLast_track() != null && !"".equals(c.getLast_track())) {
								c.setLast_track(c.getLast_track().replace("&nbsp;", "").trim());
								if (StringUtil.isNum(c.getLast_track())) {
									c.setFallow(c.getLast_track());
								} else {
									boolean flag = StringUtil.getHanzi(c.getLast_track());
									if (!flag) {
										byte[] bytes = StringUtil.hexDecode(c.getLast_track());
										String ObjContent = new String(bytes, "UTF-8");
										c.setFallow(ObjContent);
									} else {
										c.setFallow(c.getLast_track());
									}
								}
							}
							if (c.getTrackings() != null && !"".equals(c.getTrackings())) {
								c.setTracksize(String.valueOf(c.getTrackings()));
							}

						}
					}
				} catch (Exception e) {
					e.printStackTrace();
				}

				TgUserinfo userinfo = new TgUserinfo();
				userinfo.setJob("课程顾问");
				List<TgUserinfo> uList = userinfoDao.getUserInfoByUserInfo(userinfo);

				TgUserinfo userinfo1 = new TgUserinfo();
				userinfo1.setJob("在线课程顾问");
				List<TgUserinfo> uLists = userinfoDao.getUserInfoByUserInfo(userinfo1);

				List<TgState> stateList = stateDao.findAll(TgState.class);// 查询出所以的客户状态.
				result.setDefaultModel("stateList", stateList);

				result.setDefaultModel("invalid", invalid);
				result.setDefaultModel("isBySigned", isBySigned);
				result.setDefaultModel("startTime", startTime);
				result.setDefaultModel("endTime", endTime);
				result.setDefaultModel("page", page);
				result.setDefaultModel("state1", state1);
				result.setDefaultModel("list", list);
				result.setDefaultModel("uList", uList);
				result.setDefaultModel("uLists", uLists);
				result.setDefaultModel("state_s", state_s);
				return result;
			}
		});
		return new ModelAndView("consultant/consultant_client_list3", modelMap);
	}

	// 市场部客户资源列表
	@RequestMapping(value = "/consultant_client_list4")
	public ModelAndView consultant_client_list4(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, vo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String nickname = request.getParameter("nickname");
				String invalid = request.getParameter("btnInvalid");// 有效和无效
				String isBySigned = request.getParameter("isBySigned");// 根据更新时间排序
				String startTime = request.getParameter("startTime");
				String endTime = request.getParameter("endTime");
				String intention = request.getParameter("intention");
				String state1 = request.getParameter("state");
				String sname = request.getParameter("sname");
				String state_s = request.getParameter("state_s");

				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				TgUser user = UserUtil.getUserFromCookies();

				TgClient client = new TgClient();
				client.setUsername(user.getUsername());
				if (nickname != null && !"".equals(nickname) && !"null".equals(nickname)) {
					client.setNickname(nickname);
					result.setDefaultModel("nickname", nickname);
				}
				if (invalid != null && !"".equals(invalid) && !"null".equals(invalid) && !"false".equals(invalid)) {
					client.setInvalid(0);
				}
				if (startTime != null && !"".equals(startTime) && !"null".equals(startTime)) {
					try {
						Date date = sdf.parse(startTime);
						client.setStartTime(date.getTime() / 1000);
					} catch (ParseException e) {
						e.printStackTrace();
					}
				}
				if (endTime != null && !"".equals(endTime) && !"null".equals(endTime)) {
					try {
						Date date = sdf.parse(endTime);
						client.setEndTime(date.getTime() / 1000);
					} catch (ParseException e) {
						e.printStackTrace();
					}
				}
				if (sname != null && sname.equals("1")) {
					client.setUsername("");
					client.setSname("市场部问卷,市场部推广,公益讲座,传单派发");
				}
				// 判断客户状态
				if ((state1 != null && !"".equals(state1) || (state_s != null && !"".equals(state_s)))) {
					if ((state1.equals("已预约")) || state_s.equals("已预约")) {
						client.setRenum(2);
						client.setRemin(1);
					} else if (state1.equals("未出现") || state_s.equals("未出现")) {
						client.setRenum(3);
						client.setRemin(3);
					} else if (state1.equals("已缴费") || state_s.equals("已缴费")) {
						client.setRecenum(6);
						client.setRecemin(6);
					} else if (state1.equals("已测评") || state_s.equals("已测评")) {
						client.setRecenum(5);
						client.setRecemin(1);
					} else if (state1.equals("无") || state_s.equals("无")) {
						client.setRenum_n(0);

					}
				}

				if (intention != null && !"".equals(intention) && !"null".equals(intention)) {
					client.setIntention(intention);
					result.setDefaultModel("intention", intention);
				}

				Integer currPage = 1;
				if (vo.getCurrPage() != null && !"".equals(vo.getCurrPage())) {
					currPage = vo.getCurrPage();
				}

				Integer total = clientDao.getClientCount4(client);

				Page page = PageUtil.createPage(8, currPage, total);
				List<TgClient> list = new ArrayList<TgClient>();
				if (isBySigned != null && isBySigned.equals("cdate")) {
					// 根据创建时间排序
					list = clientDao.getClientByTypeCdate4(client, page);
				} else {
					// 根据更新时间排序
					list = clientDao.getTgClientByType4(client, page);
				}
				try {

					TgStudent student = new TgStudent();

					if (list != null && list.size() > 0) {
						Gson gson = new Gson();
						for (TgClient c : list) {
							// 时间和备注内容
							if (c.getMdate() != null && !"".equals(c.getMdate())) {
								String date = sdf2.format(new Date(c.getMdate() * 1000));
								c.setModeTime(date);
							}

							if (c.getCdate() != null && !"".equals(c.getCdate())) {
								String date = sdf2.format(new Date(c.getCdate() * 1000));
								c.setDateTime(date);
							}

							if (c.getPhone() != null && !"".equals(c.getPhone())) {
								if (c.getPhone().contains("[{")) {
									List<Phone> phone = gson.fromJson(c.getPhone(), new TypeToken<List<Phone>>() {
									}.getType());
									c.setPhlist(phone);
									// c.setPhone(c.getPhlist().get(0).getPhone());
								}
							}
							// 学生
							if (c.getKeyname() != null && !"".equals(c.getKeyname())) {
								student.setPkey(c.getKeyname());
								List<TgStudent> studentList = studentDao.getAgeFeature(student);
								if (studentList != null && studentList.size() > 0) {
									String stu = "";
									String context = "";

									for (int i = 0; i < studentList.size(); i++) {
										String age = studentList.get(i).getAge();
										if (age == null) {
											age = "0";
										}
										stu += studentList.get(i).getNickname() + "<span class=\"caption\">(" + age
												+ "岁" + ")</span>,";

										String con = "";
										String Contentq = "";
										if (studentList.get(i).getFeature() != null
												&& !"".equals(studentList.get(i).getFeature())) {
											studentList.get(i).setFeature(
													studentList.get(i).getFeature().replace("&nbsp;", "").trim());
											boolean flag1 = StringUtil.getHanzi(studentList.get(i).getFeature());
											if (!flag1) {
												byte[] bytes = StringUtil.hexDecode(studentList.get(i).getFeature());
												Contentq += new String(bytes, "UTF-8");
												if (Contentq != null && !"".equals(Contentq)) {
													con = studentList.get(i).getNickname() + ":(" + Contentq + ")";
												}
											} else {
												if (studentList.get(i).getFeature() != null
														&& !"".equals(studentList.get(i).getFeature())) {
													con = studentList.get(i).getNickname() + ":("
															+ studentList.get(i).getFeature() + ")";
												}
											}
											if (con != null && !"".equals(con)) {
												context = context + con + "</br>";
												if (context.contains("\"")) {
													context = context.replace('"', ' ');
												}
											}
										}
										c.setFeature(context);
									}
									c.setStudent(stu);
								}
							}
							// 客户状态
							String stat = "";
							if (c.getState() != null && !"".equals(c.getState())) {
								int renum = c.getState();
								if (renum >= 1 && renum <= 2) {
									stat = "已预约";
								} else if (renum == 3) {
									stat = "未出现";
								}
								c.setStates(stat);
							}

							if (c.getWorth() != null && !"".equals(c.getWorth())) {
								Integer recenum = c.getWorth();
								if (recenum == 6) {
									if (stat != "") {
										stat = stat + "," + "已缴费";
									} else {
										stat = "已缴费";
									}
								} else if (0 < recenum && recenum <= 5) {
									if (stat != "") {
										stat = stat + "," + "已测评";
									} else {
										stat = "已测评";
									}
								}
								c.setStates(stat);
							}

							// 最后更新信息和状态和总更新数量
							if (c.getLastdate() != null && !"".equals(c.getLastdate())) {
								String createTime = sdf2.format(new Date(c.getLastdate() * 1000));
								c.setNewTime(createTime);
							}

							if (c.getLast_track() != null && !"".equals(c.getLast_track())) {
								c.setLast_track(c.getLast_track().replace("&nbsp;", "").trim());
								if (StringUtil.isNum(c.getLast_track())) {
									c.setFallow(c.getLast_track());
								} else {
									boolean flag = StringUtil.getHanzi(c.getLast_track().replaceAll("</?[^<]+>", ""));
									if (!flag) {
										byte[] bytes = StringUtil.hexDecode(c.getLast_track());
										String ObjContent = new String(bytes, "UTF-8");
										c.setFallow(ObjContent);
									} else {
										c.setFallow(c.getLast_track());
									}
								}
								if (c.getFallow().contains("\"")) {
									c.setFallow(c.getFallow().replace('"', ' '));
								}
							}

							if (c.getTrackings() != null && !"".equals(c.getTrackings())) {
								c.setTracksize(String.valueOf(c.getTrackings()));
							}
						}
					}
				} catch (Exception e) {
					e.printStackTrace();
				}

				TgUserinfo userinfo = new TgUserinfo();
				userinfo.setJob("课程顾问");
				List<TgUserinfo> uList = userinfoDao.getUserInfoByUserInfo(userinfo);

				userinfo.setJob("在线课程顾问");
				List<TgUserinfo> uLists = userinfoDao.getUserInfoByUserInfo(userinfo);

				List<TgState> stateList = stateDao.findAll(TgState.class);
				result.setDefaultModel("stateList", stateList);

				result.setDefaultModel("invalid", invalid);
				result.setDefaultModel("isBySigned", isBySigned);
				result.setDefaultModel("startTime", startTime);
				result.setDefaultModel("endTime", endTime);
				result.setDefaultModel("page", page);
				result.setDefaultModel("state1", state1);
				result.setDefaultModel("list", list);
				result.setDefaultModel("uList", uList);
				result.setDefaultModel("uLists", uLists);
				result.setDefaultModel("state_s", state_s);
				result.setDefaultModel("sname", sname);
				return result;
			}
		});
		return new ModelAndView("consultant/consultant_client_list4", modelMap);
	}

	// 添加客户资源跟踪
	@RequestMapping(value = "/add_client_follow")
	public ModelAndView add_client_follow(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String keyname = request.getParameter("keyname");
				String states = request.getParameter("states");
				String protime = request.getParameter("protime");
				String state = request.getParameter("state");
				String reserve_key = request.getParameter("reserve_key");
				String target = request.getParameter("target");
				String remark = HtmlUtils.deleteAllHTMLTag(request.getParameter("remark"));

				TgUser user = UserUtil.getUserFromCookies();
				// 检查和改变新转客户列表的状态
				TgClient client = new TgClient();
				client.setKeyname(keyname);
				List<TgClient> list = clientDao.findByExample(client);
				if (list != null && list.size() > 0) {
					client = list.get(0);
					if (client.getLodusername() != null && !"".equals(client.getLodusername())) {
						client.setUsername(user.getUsername());
						client.setLodusername(" ");
						client.setRdate(client.getCdate());
						client.setMdate(new Date().getTime() / 1000);
						client.setCdate(new Date().getTime() / 1000);
						clientDao.update(client);
					}
					if (target != null && !"".equals(target)) {
						client.setLodusername(target);
						client.setUsername(target);
						client.setMdate(new Date().getTime() / 1000);
						clientDao.update(client);

						if (client.getType() != null && !"".equals(client.getType())) {
							/* if(client.getType()==1){ */
							JsVote vote = new JsVote();
							vote = voteDao.findById(JsVote.class, client.getFrom_id());
							vote.setUsername(target);
							voteDao.update(vote);
							// }
							/*
							 * if(client.getType()==2){ JsFromUser fromuser =
							 * new JsFromUser(); fromuser =
							 * fromuserDao.findById(JsFromUser.class,
							 * client.getFrom_id());
							 * fromuser.setUsername(target);
							 * fromuserDao.update(fromuser); }
							 * if(client.getType()==3){ TgClientImp clientImp =
							 * new TgClientImp(); clientImp =
							 * clientImpDao.findById(TgClientImp.class,
							 * client.getFrom_id());
							 * clientImp.setTo_username(target);
							 * clientImpDao.update(clientImp); }
							 */
						}
					}
				}

				TgReserve reserve = new TgReserve();
				if (reserve_key != null && !"".equals(reserve_key)) {
					reserve.setKeyname(reserve_key);
					List<TgReserve> reservelist = reserveDao.findByExample(reserve);
					if (state != null && !"".equals(state)) {
						if (reservelist != null && reservelist.size() > 0) {
							reserve = reservelist.get(0);
							reserve.setState(Integer.parseInt(state));
							reserve.setMdate(new Date().getTime() / 1000);
							reserveDao.update(reserve);
						}
					}
				}

				TgTracking tra = new TgTracking();
				tra.setClient(keyname);
				List<TgTracking> tralist = trackingDao.findByExample(tra);
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				Date now = new Date();
				try {
					String hehe = sdf.format(now);
					if (tralist != null && tralist.size() > 0) {
						if ((states != null && !"".equals(states)) || (remark != null && !"无".equals(remark))) {
							if (tralist.get(0).getCdate() != null && !"".equals(tralist.get(0).getCdate())) {
								String createTime = sdf.format(new Date(tralist.get(0).getCdate() * 1000));
								TgTracking tras = new TgTracking();
								tras = tralist.get(0);
								if (hehe.equals(createTime)) {
									tras.setKeyname(tralist.get(0).getKeyname());
									tras.setClient(keyname);
									tras.setId(tralist.get(0).getId());
									if (states != null && !"".equals(states)) {
										tras.setState(states);
									}
									if (remark != null && !"无".equals(remark)) {
										tras.setRemark(remark);
									}
									if (protime != null && !"".equals(protime)) {
										Date date = sdf.parse(protime);
										tras.setRemind_date(date.getTime() / 1000);
									}
									tras.setUsername(user.getUsername());
									tras.setMdate(new Date().getTime() / 1000);
									trackingDao.update(tras);
								} else {
									tra.setState(states);
									tra.setKeyname(SsiUtils.randomUUID());
									tra.setRemark(remark);
									if (protime != null && !"".equals(protime)) {
										Date date = sdf.parse(protime);
										tra.setRemind_date(date.getTime() / 1000);
									}
									tra.setUsername(user.getUsername());
									tra.setCdate(new Date().getTime() / 1000);
									tra.setMdate(new Date().getTime() / 1000);
									trackingDao.insert(tra);
								}
							}
						}
					} else {
						if ((states != null && !"".equals(states)) || (remark != null && !"无".equals(remark))) {
							tra.setState(states);
							tra.setKeyname(SsiUtils.randomUUID());
							tra.setRemark(remark);
							if (protime != null && !"".equals(protime)) {
								Date date = sdf.parse(protime);
								tra.setRemind_date(date.getTime() / 1000);
							}
							tra.setUsername(user.getUsername());
							tra.setCdate(new Date().getTime() / 1000);
							tra.setMdate(new Date().getTime() / 1000);
							trackingDao.insert(tra);
						}
					}

				} catch (ParseException e) {
					e.printStackTrace();
				}
				result.setDefaultModel("state", state);
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	// 客户资源列表--客户资源详情
	@RequestMapping(value = "/consultant_client")
	public ModelAndView consultant_client_view(ModelMap modelMap, final LoginVo loginVo,
			final HttpServletRequest request, final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, loginVo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				TgUser user1 = UserUtil.getUserFromCookies();
				String keyname = request.getParameter("keyname");
				String type = request.getParameter("type");

				TgClient client = new TgClient();
				client.setKeyname(keyname);
				List<TgClient> list = clientDao.getClientByKeyname(client);
				if (list != null && list.size() > 0) {
					client = list.get(0);
					if (client.getDescs() != null && !"".equals(client.getDescs())) {
						boolean flag = StringUtil.getHanzi(client.getDescs());
						if (!flag) {
							try {
								byte[] bytes = StringUtil.hexDecode(client.getDescs());
								String ObjContent = new String(bytes, "UTF-8");
								client.setDescs(ObjContent);
							} catch (Exception e) {
								e.printStackTrace();
							}
						} else {
							if (client.getDescs().contains("备注:")) {
								client.setDescs(client.getDescs().replace("备注:", ""));
							}
						}
					}
					String quests = client.getQuests();
					if (quests != null && !"".equals(quests) && !"[]".equals(quests)) {
						String ObjContent = "";
						boolean flag = StringUtil.getHanzi(quests);
						if (!flag) {
							try {
								byte[] bytes = StringUtil.hexDecode(quests);
								ObjContent = new String(bytes, "UTF-8");
							} catch (Exception e) {
								e.printStackTrace();
							}
						} else {
							ObjContent = quests;
						}

						try {
							JSONArray array = new JSONArray(ObjContent);
							List<Quests> quesList = new ArrayList<Quests>();
							if (array != null && !"".equals(array)) {
								for (int i = 0; i < array.length(); i++) {
									Gson gson = new Gson();
									Quests quest = new Quests();
									quest = gson.fromJson(array.get(i).toString(), Quests.class);
									quesList.add(quest);
								}
								client.setQueList(quesList);
							}
						} catch (JSONException e) {
							e.printStackTrace();
						}
					}
					// 解析出电话，关系
					String phone = client.getPhone();
					if (phone != null && !"".equals(phone)) {
						Gson gson = new Gson();
						if (phone.contains("[{")) {
							List<Phone> ph = gson.fromJson(phone, new TypeToken<List<Phone>>() {
							}.getType());
							client.setPhlist(ph);
						}
					}
				}

				TgStudent student = new TgStudent();
				student.setPkey(keyname);
				List<TgStudent> stuList = studentDao.findByExample(student);
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

				if (stuList != null && stuList.size() > 0) {
					for (TgStudent stu : stuList) {
						// 生日转换
						if (stu.getBirthday() != null && !"".equals(stu.getBirthday())) {
							String birthdays = sdf.format((stu.getBirthday() * 1000));
							stu.setBirthdays(birthdays);
						}
						// 备注文字解密
						if (stu.getFeature() != null && !"".equals(stu.getFeature())) {
							boolean flag = StringUtil.getHanzi(stu.getFeature());
							if (!flag) {
								try {
									byte[] bytes = StringUtil.hexDecode(stu.getFeature());
									String ObjContent = new String(bytes, "UTF-8");
									stu.setFeature(ObjContent);
								} catch (Exception e) {
									e.printStackTrace();
								}
							}
						}
					}
				}

				TgTracking track = new TgTracking();
				track.setClient(keyname);
				List<TgTracking> traList = trackingDao.findByExample(track);
				if (traList != null && traList.size() > 0) {
					TgState state = new TgState();

					for (TgTracking tra : traList) {
						// 状态
						if (tra.getState() != null && !"".equals(tra.getState())) {
							if (tra.getState().contains(",")) {
								String[] stat = tra.getState().split(",");
								if (stat.getClass().isArray()) {
									String stats = "";
									for (int i = 0; i < stat.length; i++) {
										state.setKeyname(stat[i]);
										List<TgState> stateList = stateDao.findByExample(state);
										if (stateList != null && stateList.size() > 0) {
											stats = stats + stateList.get(0).getName() + ",";
										}
									}
									String[] sta = stats.split(",");
									List<State> staList = new ArrayList<State>();
									List<String> person = new ArrayList<>(Arrays.asList(sta));
									for (int j = 0; j < person.size(); j++) {
										State states = new State();
										states.setState(person.get(j));
										staList.add(states);
									}
									tra.setSlist(staList);
								}
							} else {
								state.setKeyname(tra.getState());
								List<TgState> stateList = stateDao.findByExample(state);
								if (stateList != null && stateList.size() > 0) {
									tra.setState(stateList.get(0).getName());
								}
							}
						}
						// 时间
						if (tra.getRemind_date() != null && !"".equals(tra.getRemind_date())) {
							String createTime = sdf.format(new Date(tra.getRemind_date() * 1000));
							tra.setStartTime(createTime);
						}
						// 备注内容
						if (tra.getRemark() != null && !"".equals(tra.getRemark())) {
							if (StringUtil.isNum(tra.getRemark())) {
								tra.setRemark(tra.getRemark());
							} else {
								boolean flag = StringUtil.getHanzi(tra.getRemark());
								if (!flag) {
									try {
										byte[] bytes = StringUtil.hexDecode(tra.getRemark());
										String ObjContent = new String(bytes, "UTF-8");
										tra.setRemark(ObjContent);
									} catch (Exception e) {
										e.printStackTrace();
									}
								}
							}

						}

						// 负责人
						TgUserinfo user = new TgUserinfo();
						user.setUsername(tra.getUsername());
						List<TgUserinfo> ulist = userinfoDao.findByExample(user);
						if (ulist != null && ulist.size() > 0) {
							tra.setNickname(ulist.get(0).getNickname());
						}
						// 时间转换
						if (tra.getCdate() != null && !"".equals(tra.getCdate())) {
							String createTime = sdf1.format(new Date(tra.getCdate() * 1000));
							tra.setCreateTime(createTime);
						}

					}
				}
				TgUserinfo userinfo = new TgUserinfo();
				userinfo.setJob("课程顾问");
				List<TgUserinfo> uList = userinfoDao.getUserInfoByUserInfo(userinfo);

				TgUserinfo userinfo1 = new TgUserinfo();
				userinfo.setJob("在线课程顾问");
				List<TgUserinfo> uLists = userinfoDao.getUserInfoByUserInfo(userinfo1);

				List<TgSource> souList = sourceDao.findAll(TgSource.class);
				List<TgCategory> cateList = categoryDao.findAll(TgCategory.class);

				result.setDefaultModel("type", type);
				result.setDefaultModel("keyname", keyname);
				result.setDefaultModel("traList", traList);
				result.setDefaultModel("souList", souList);
				result.setDefaultModel("cateList", cateList);
				result.setDefaultModel("client", client);
				result.setDefaultModel("stuList", stuList);
				result.setDefaultModel("uList", uList);
				result.setDefaultModel("uLists", uLists);
				return result;
			}
		});
		return new ModelAndView("consultant/consultant_client", modelMap);
	}

	// 资源跟踪记录列表
	@RequestMapping(value = "/get_client_follow")
	public ModelAndView get_client_follow(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String keyname = request.getParameter("keyname");
				TgTracking tracking = new TgTracking();
				tracking.setClient(keyname);
				List<TgTracking> list = trackingDao.findByExample(tracking);
				SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

				if (list != null && list.size() > 0) {
					TgState state = new TgState();

					for (TgTracking tra : list) {
						// 状态
						if (tra.getState() != null && !"".equals(tra.getState())) {
							String[] s = tra.getState().split(",");
							if (s.length == 1) {
								state.setKeyname(s[0]);
								List<TgState> stateList = stateDao.findByExample(state);
								if (stateList != null && stateList.size() > 0) {
									tra.setState(stateList.get(0).getName());
								}
							} else if (s.length == 2) {
								state.setKeyname(s[0]);
								List<TgState> stateList = stateDao.findByExample(state);
								if (stateList != null && stateList.size() > 0) {
									tra.setState(stateList.get(0).getName());
								}

								state.setKeyname(s[1]);
								List<TgState> stateList2 = stateDao.findByExample(state);
								if (stateList2 != null && stateList2.size() > 0) {
									tra.setState2(stateList2.get(0).getName());
								}
							} else if (s.length == 3) {
								state.setKeyname(s[0]);
								List<TgState> stateList = stateDao.findByExample(state);
								if (stateList != null && stateList.size() > 0) {
									tra.setState(stateList.get(0).getName());
								}

								state.setKeyname(s[1]);
								List<TgState> stateList2 = stateDao.findByExample(state);
								if (stateList2 != null && stateList2.size() > 0) {
									tra.setState2(stateList2.get(0).getName());
								}

								state.setKeyname(s[2]);
								List<TgState> stateList3 = stateDao.findByExample(state);
								if (stateList3 != null && stateList3.size() > 0) {
									tra.setState3(stateList3.get(0).getName());
								}
							}

						}
						// 备注内容
						if (tra.getRemark() != null && !"".equals(tra.getRemark())) {
							if (StringUtil.isNum(tra.getRemark())) {
								tra.setRemark(tra.getRemark());
							} else {
								boolean flag = StringUtil.getHanzi(tra.getRemark());
								if (!flag) {
									try {
										byte[] bytes = StringUtil.hexDecode(tra.getRemark());
										String ObjContent = new String(bytes, "UTF-8");
										tra.setRemark(ObjContent);
									} catch (Exception e) {
										e.printStackTrace();
									}
								}
							}
						}
						// 负责人
						TgUserinfo user = new TgUserinfo();
						user.setUsername(tra.getUsername());
						List<TgUserinfo> ulist = userinfoDao.findByExample(user);
						if (ulist != null && ulist.size() > 0) {
							tra.setNickname(ulist.get(0).getNickname());
						}
						// 时间转换
						if (tra.getCdate() != null && !"".equals(tra.getCdate())) {
							String createTime = sdf1.format(new Date(tra.getCdate() * 1000));
							tra.setCreateTime(createTime);
						}
						// 提醒时间转换
						if (tra.getRemind_date() != null && !"".equals(tra.getRemind_date())) {
							String createTime = sdf.format(new Date(tra.getRemind_date() * 1000));
							tra.setStartTime(createTime);
						}
					}
				}

				// 学生信息
				TgStudent student = new TgStudent();
				student.setPkey(keyname);
				List<TgStudent> stuList = studentDao.findByExample(student);
				if (stuList != null && stuList.size() > 0) {
					for (TgStudent stu : stuList) {
						// 生日转换
						if (stu.getBirthday() != null && !"".equals(stu.getBirthday())) {
							String birthdays = sdf.format(new Date(stu.getBirthday() * 1000));
							stu.setBirthdays(birthdays);
						}
						// 备注文字解密
						if (stu.getFeature() != null && !"".equals(stu.getFeature())) {
							boolean flag = StringUtil.getHanzi(stu.getFeature());
							if (!flag) {
								try {
									byte[] bytes = StringUtil.hexDecode(stu.getFeature());
									String ObjContent = new String(bytes, "UTF-8");
									stu.setFeature(ObjContent);
								} catch (Exception e) {
									e.printStackTrace();
								}
							}
						}
					}
				}
				result.setDefaultModel("list", list);
				result.setDefaultModel("stuList", stuList);
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	// 客户资源跟踪--功能为转接
	@RequestMapping(value = "/consultant_client_follow")
	public ModelAndView consultant_client_follow(ModelMap modelMap, final LoginVo loginVo, HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, loginVo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				List<TgSource> souList = sourceDao.findAll(TgSource.class);
				List<TgCategory> cateList = categoryDao.findAll(TgCategory.class);

				result.setDefaultModel("souList", souList);
				result.setDefaultModel("cateList", cateList);
				return result;
			}
		});
		return new ModelAndView("consultant/consultant_client_follow", modelMap);
	}

	// 客户预约
	@RequestMapping(value = "/consultant_client_reserve")
	public ModelAndView consultant_client_reserve(ModelMap modelMap, final LoginVo loginVo,
			final HttpServletRequest request, final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, loginVo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				try {
					String date = request.getParameter("datetime");
					String region = request.getParameter("region");

					Map<String, String[]> dateMap = Constants.dateMap;
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

					TgUser user = UserUtil.getUserFromCookies();
					TgUserinfo userinfo = new TgUserinfo();
					userinfo.setUsername(user.getUsername());
					List<TgUserinfo> list = userinfoDao.findByExample(userinfo);
					if (region != null && !"".equals(region)) {

					} else {
						if (user.getRegion().equals("CCEE06DEB51D")) {
							region = "svah5207yg3i";
						} else {
							region = user.getRegion();
						}
					}

					if (region != null && !"".equals(region)) {
						TgOffice office = new TgOffice();
						office.setKeyname(region);
						List<TgOffice> offList = tgOfficeDao.findByExample(office);
						if (offList != null && offList.size() > 0) {
							office = offList.get(0);
							boolean flag = StringUtil.getHanzi(office.getNotice());
							if (!flag) {
								byte[] bytes = StringUtil.hexDecode(office.getNotice());
								String ObjContent = new String(bytes, "UTF-8");
								office.setNotice(ObjContent);
							}
							result.setDefaultModel("office", office);
						}
					}

					String today = "";
					String BeforetwoDay = "";
					String BeforeDay = "";
					String tommorrow1 = "";
					String tommorrow2 = "";
					String tommorrow3 = "";
					String tommorrow4 = "";
					String newday = "";
					Date currentDate = null;
					if (date != null && !"".equals(date)) {
						currentDate = sdf.parse(date);// 今天
						newday = date;
						Calendar rightNow = Calendar.getInstance();
						rightNow.setTime(currentDate);
						rightNow.add(Calendar.DAY_OF_YEAR, -1);
						String ate = sdf.format(rightNow.getTime());
						currentDate = sdf.parse(ate);
					} else {
						newday = sdf.format(DateUtil.getToDay());
						currentDate = new Date();
						Calendar rightNow = Calendar.getInstance();
						rightNow.setTime(currentDate);
						rightNow.add(Calendar.DAY_OF_YEAR, -1);
						String ate = sdf.format(rightNow.getTime());
						currentDate = sdf.parse(ate);
					}
					List<Date> days = DateUtil.dateToWeek(currentDate);
					if (days != null && days.size() > 0) {
						BeforetwoDay = sdf.format(days.get(0)).substring(0, 10);
						BeforeDay = sdf.format(days.get(1)).substring(0, 10);
						today = sdf.format(days.get(2)).substring(0, 10);
						tommorrow1 = sdf.format(days.get(3)).substring(0, 10);
						tommorrow2 = sdf.format(days.get(4)).substring(0, 10);
						tommorrow3 = sdf.format(days.get(5)).substring(0, 10);
						tommorrow4 = sdf.format(days.get(6)).substring(0, 10);
					}

					List<TgOffice> office_List = tgOfficeDao.findAll(TgOffice.class);

					// 查找咨询师
					TgUserinfo user_info = new TgUserinfo();
					user_info.setJob("课程顾问");
					if (region != null && !"".equals(region)) {
						user_info.setRegion(region);
					} else {
						user_info.setRegion("svah5207yg3i");
					}

					TgUserinfo user_info1 = new TgUserinfo();
					user_info1.setJob("在线课程顾问");
					if (region != null && !"".equals(region)) {
						user_info1.setRegion(region);
					} else {
						user_info1.setRegion("svah5207yg3i");
					}

					List<TgUserinfo> uList = userinfoDao.getUserInfoByUserInfo(user_info);

					List<TgUserinfo> uList1 = userinfoDao.getUserInfoByUserInfo(user_info1);

					result.setDefaultModel("office_List", office_List);

					result.setDefaultModel("uList1", uList1);
					result.setDefaultModel("region", region);
					result.setDefaultModel("dateMap", dateMap);
					result.setDefaultModel("BeforetwoDay", BeforetwoDay);
					result.setDefaultModel("BeforeDay", BeforeDay);
					result.setDefaultModel("today", today);
					result.setDefaultModel("tommorrow1", tommorrow1);
					result.setDefaultModel("tommorrow2", tommorrow2);
					result.setDefaultModel("tommorrow3", tommorrow3);
					result.setDefaultModel("tommorrow4", tommorrow4);
					result.setDefaultModel("newday", newday);
					result.setDefaultModel("uList", uList);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return result;
			}
		});
		return new ModelAndView("consultant/consultant_client_reserve", modelMap);
	}

	// 异步获取预约
	@RequestMapping(value = "/get_client_reserve")
	public ModelAndView get_client_reserve(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String startTime = request.getParameter("date");
				String region = request.getParameter("region");
				TgReserve reserve = new TgReserve();
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

				if (region != null && !"".equals(region)) {
					reserve.setRegion(region);
				} else {
					reserve.setRegion("svah5207yg3i");
				}

				String BeforetwoDay = "";
				String tommorrow4 = "";
				Date currentDate = null;
				if (startTime != null && !"".equals(startTime)) {
					try {
						currentDate = sdf.parse(startTime);
					} catch (ParseException e) {
						e.printStackTrace();
					} // 今天
					Calendar rightNow = Calendar.getInstance();
					rightNow.setTime(currentDate);
					rightNow.add(Calendar.DAY_OF_YEAR, -1);
					String ate = sdf.format(rightNow.getTime());
					try {
						currentDate = sdf.parse(ate);
					} catch (ParseException e) {
						e.printStackTrace();
					}
				} else {
					currentDate = new Date();
					Calendar rightNow = Calendar.getInstance();
					rightNow.setTime(currentDate);
					rightNow.add(Calendar.DAY_OF_YEAR, -1);
					String ate = sdf.format(rightNow.getTime());
					try {
						currentDate = sdf.parse(ate);
					} catch (ParseException e) {
						e.printStackTrace();
					}
				}
				List<Date> days = DateUtil.dateToWeek(currentDate);

				if (days != null && days.size() > 0) {
					BeforetwoDay = sdf.format(days.get(0)).substring(0, 10);
					tommorrow4 = sdf.format(days.get(6)).substring(0, 10);
				}

				reserve.setStartTime(BeforetwoDay);
				reserve.setEndTime(tommorrow4);
				SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				List<TgReserve> list = reserveDao.getReserveByTime(reserve);
				if (list != null && list.size() > 0) {
					for (TgReserve res : list) {
						// 时间转成String
						TgStudent student = new TgStudent();
						if (res.getDate() != null && !"".equals(res.getDate())) {
							res.setDates(sdf.format(res.getDate()));
						}
						if (res.getCdate() != null && !"".equals(res.getCdate())) {
							String date = sdf1.format(new Date(res.getCdate() * 1000));
							res.setStartTime(date);
						}
						// 获取学生信息
						List<TgStudent> stuList = new ArrayList<TgStudent>();
						student.setPkey(res.getClient());
						List<TgStudent> sList = studentDao.findByExample(student);
						if (sList != null && sList.size() > 0) {
							for (int i = 0; sList.size() > i; i++) {
								student = sList.get(i);
								stuList.add(student);
							}
						}
						res.setStudents(stuList);
					}
				}
				result.setDefaultModel("list", list);
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	// 预约数据查询
	@RequestMapping(value = "/consultant_client_reserve_list")
	public ModelAndView consultant_client_reserve_list(ModelMap modelMap, final BaseVo vo,
			final HttpServletRequest request, final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, vo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String nickname = request.getParameter("nickname");
				String receptioner = request.getParameter("receptioner");
				String address = request.getParameter("address");
				String phone = request.getParameter("phone");
				String email = request.getParameter("email");
				String qq = request.getParameter("qq");
				String sdate = request.getParameter("sdate");
				String edate = request.getParameter("edate");
				String sdate1 = request.getParameter("sdate1");
				String edate1 = request.getParameter("edate1");
				String region = request.getParameter("region");
				String state = request.getParameter("state");
				String is_signer = request.getParameter("is_signer");
				String is_receptioner = request.getParameter("is_receptioner");
				String reserve_ns = request.getParameter("reserve_ns");
				String source = request.getParameter("source");
				String update_user = request.getParameter("update_user");
				String weixin = request.getParameter("weixin");

				TgUser user = UserUtil.getUserFromCookies();
				TgReserve reserve = new TgReserve();

				if (nickname != null && !"".equals(nickname)) {
					reserve.setNickname(nickname);
				}
				if (weixin != null && !"".equals(weixin)) {
					reserve.setWeixin(weixin);
				}
				if (address != null && !"".equals(address)) {
					reserve.setAdcity(address);
				}
				if (reserve_ns != null && !"".equals(reserve_ns)) {
					reserve.setReserve_ns(reserve_ns);
				}
				if (receptioner != null && !"".equals(receptioner)) {
					reserve.setReceptioner(receptioner);
				}
				if (qq != null && !"".equals(qq)) {
					reserve.setQq(qq);
				}
				if (email != null && !"".equals(email)) {
					reserve.setEmail(email);
				}
				if (phone != null && !"".equals(phone)) {
					reserve.setPhone(phone);
				}
				if (region != null && !"".equals(region)) {
					reserve.setRegion(region);
				}
				if (state != null && !"".equals(state)) {
					int stat = Integer.parseInt(state);
					reserve.setState(stat);
				}
				if (is_signer != null && is_signer.equals("1")) {
					reserve.setUsername(user.getUsername());
				}
				if (is_receptioner != null && is_receptioner.equals("1")) {
					reserve.setReception_u(user.getUsername());
				}
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				if (sdate != null && !"".equals(sdate)) {
					try {
						reserve.setSdate(sdf.parse(sdate));
					} catch (ParseException e) {
						e.printStackTrace();
					}
				}
				if (edate != null && !"".equals(edate)) {
					try {
						reserve.setEdate(sdf.parse(edate));
					} catch (ParseException e) {
						e.printStackTrace();
					}
				}
				if (sdate1 != null && !"".equals(sdate1)) {
					try {
						reserve.setSdate1(sdf.parse(sdate1).getTime() / 1000);
						// System.out.println(reserve.getSdate1());
					} catch (ParseException e) {
						e.printStackTrace();
					}
				}
				if (edate1 != null && !"".equals(edate1)) {
					try {
						reserve.setEdate1(sdf.parse(edate1).getTime() / 1000);
						// System.out.println(reserve.getEdate1());
					} catch (ParseException e) {
						e.printStackTrace();
					}
				}
				if (source != null && !"".equals(source)) {
					reserve.setSourcens(source);
				}

				if (update_user != null && !"".equals(update_user)) {
					reserve.setUpdate_user(update_user);
				}

				Integer currPage = 1;
				if (vo.getCurrPage() != null && !"".equals(vo.getCurrPage())) {
					currPage = vo.getCurrPage();
				}
				Integer total = reserveDao.getReserveCount(reserve);
				Page page = PageUtil.createPage(8, currPage, total);
				List<TgReserve> list = reserveDao.getReserveList(reserve, page);
				TgTracking tracking = new TgTracking();
				if (list != null && list.size() > 0) {
					for (TgReserve res : list) {
						tracking.setClient(res.getClient());
						List<TgTracking> listsize = trackingDao.findByExample(tracking);
						res.setTracksize(listsize.size() + "");
						if (res.getCdate() != null && !"".equals(res.getCdate())) {
							String cdate = sdf1.format(new Date(res.getCdate() * 1000));
							res.setStartTime(cdate);
						}
						/**
						 * 修改人及修改时间不为空
						 */
						if (MathUtil.isNotEmpty(res.getUpdate_user())
								&& MathUtil.isNotEmpty(res.getUpdate_user_time())) {
							String[] strUsers = res.getUpdate_user().split(",");
							String[] strUserTimes = res.getUpdate_user_time().split(",");
							List<String> update_Users = Arrays.asList(strUsers);
							List<String> update_UserTimes = Arrays.asList(strUserTimes);
							res.setUpdate_Users(update_Users);
							res.setUpdate_UserTimes(update_UserTimes);
						}
					}
				}
				String username = user.getUsername();
				if (username.equals("yuanjing") || username.equals("he") || username.equals("system")) {
					result.setDefaultModel("user", username);
				}

				List<TgOffice> offList = tgOfficeDao.findAll(TgOffice.class);

				result.setDefaultModel("offlist", offList);
				result.setDefaultModel("nickname", nickname);
				result.setDefaultModel("receptioner", receptioner);
				result.setDefaultModel("address", address);
				result.setDefaultModel("sdate", sdate);
				result.setDefaultModel("edate", edate);
				result.setDefaultModel("sdate1", sdate1);
				result.setDefaultModel("edate1", edate1);
				result.setDefaultModel("qq", qq);
				result.setDefaultModel("phone", phone);
				result.setDefaultModel("email", email);
				result.setDefaultModel("region", region);
				result.setDefaultModel("state", state);
				result.setDefaultModel("is_signer", is_signer);
				result.setDefaultModel("is_receptioner", is_receptioner);
				result.setDefaultModel("source", source);
				result.setDefaultModel("update_user", update_user);
				result.setDefaultModel("list", list);
				result.setDefaultModel("page", page);
				return result;
			}
		});
		return new ModelAndView("consultant/consultant_client_reserve_list", modelMap);
	}

	/**
	 * @Title: 方法名：setNewYuyueRen
	 * @Description: 功能描述：设置最终预约人
	 * @author hqD ☺ ^o^
	 * @date 2017年12月21日 下午3:41:43
	 * @param @param
	 *            pic
	 * @param @param
	 *            request
	 * @param @param
	 *            response
	 * @return void 返回类型
	 * @throws IOException
	 * @throws ParseException
	 */
	@RequestMapping(value = "/setNewYuyueRen")
	public void setNewYuyueRen(HttpServletResponse response, String id, String userName, Integer index,
			String oldUserName) throws IOException, ParseException {
		String flge = "false";
		if (MathUtil.isNotEmpty(id) && MathUtil.isNotEmpty(userName)) {
			TgReserve reserve = reserveDao.getTg_reserve_Id(id);
			// 原始的预约人
			TgUserinfo oldUserinfo = userinfoDao.getTeacherByNickName(oldUserName);
			// 新的预约人
			TgUserinfo newUserinfo = userinfoDao.getTeacherByNickName(userName);

			if (MathUtil.isNotEmpty(reserve) && MathUtil.isNotEmpty(oldUserinfo) && MathUtil.isNotEmpty(newUserinfo)) {
				reserve.setUsername(newUserinfo.getUsername());
				String[] strUsers = reserve.getUpdate_user().split(",");
				String[] strUpdateTimes = reserve.getUpdate_user_time().split(",");
				String newUpdateUser = "";
				String newUpdateTime = "";
				for (int i = 0; i < strUsers.length; i++) {
					if (i == index) {
						// 设置新的预约时间(根据空格分割成 例如‘2017-08-01’ ‘10:00’)
						String[] newYuyueTime = strUpdateTimes[i].split("\\s");
						System.out.println("数组： " + newYuyueTime);
						reserve.setDate(sdf.parse(newYuyueTime[0]));
						reserve.setTime(newYuyueTime[1]);
						newUpdateUser += oldUserName + ",";
						newUpdateTime += sdf.format(reserve.getDate()) + " " + reserve.getTime() + ",";
					} else {
						newUpdateUser += strUsers[i] + ",";
						newUpdateTime += strUpdateTimes[i] + ",";
					}
				}
				reserve.setUpdate_user(newUpdateUser);
				reserve.setUpdate_user_time(newUpdateTime);
				reserveDao.update(reserve);
				flge = "true";
			}
			PrintWriter writer = response.getWriter();
			writer.print(flge);
		}
	}

	// 异步获取预约客户
	@RequestMapping(value = "/consultant_reserve_user")
	public ModelAndView consultant_reserve_user(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String nickname = request.getParameter("nickname");
				String time = request.getParameter("time");
				String rep_date = request.getParameter("rep_date");
				String region = request.getParameter("region");

				TgReserve reserve = new TgReserve();

				if (nickname != null && !"".equals(nickname)) {
					reserve.setNickname(nickname);
				}
				if (rep_date != null && !"".equals(rep_date)) {
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
					Date date = null;
					try {
						date = sdf.parse(rep_date);
					} catch (ParseException e) {
						e.printStackTrace();
					}
					reserve.setDatec(date.getTime() / 1000);
				}
				if (time != null && !"".equals(time)) {
					reserve.setTime(time);
				}
				if (region != null && !"".equals(region)) {
					reserve.setRegion(region);
				}

				Integer currPage = 1;
				if (vo.getCurrPage() != null && !"".equals(vo.getCurrPage())) {
					currPage = vo.getCurrPage();
				}
				Integer total = reserveDao.getReserveCount(reserve);
				Page page = PageUtil.createPage(8, currPage, total);
				List<TgReserve> list = reserveDao.getReserveList(reserve, page);
				SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");

				TgTracking tracking = new TgTracking();
				if (list != null && list.size() > 0) {
					for (TgReserve res : list) {
						tracking.setClient(res.getClient());
						List<TgTracking> listsize = trackingDao.findByExample(tracking);
						res.setTracksize(listsize.size() + "");

						if (res.getCdate() != null && !"".equals(res.getCdate())) {
							String date = sdf1.format(new Date(res.getCdate() * 1000));
							res.setStartTime(date);
						}
						if (res.getDate() != null && !"".equals(res.getDate())) {
							String date1 = sdf2.format(res.getDate());
							res.setDates(date1);
						}

						if (res.getPhone() != null && !"".equals(res.getPhone())) {
							if (res.getPhone().contains("[{")) {
								Gson gson = new Gson();
								List<Phone> ph = gson.fromJson(res.getPhone(), new TypeToken<List<Phone>>() {
								}.getType());
								res.setPhlist(ph);
								if (res.getPhone() != null && !"[]".equals(res.getPhlist())) {
									res.setPhone(res.getPhlist().get(0).getPhone());
								}
							}
						}
					}
				}

				List<TgOffice> offList = tgOfficeDao.findAll(TgOffice.class);

				result.setDefaultModel("offlist", offList);
				result.setDefaultModel("nickname", nickname);
				result.setDefaultModel("list", list);
				result.setDefaultModel("page", page);
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	// 获取中心地址
	@RequestMapping(value = "/consultant_office_get")
	public ModelAndView consultant_office_get(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				List<TgOffice> list = tgOfficeDao.findAll(TgOffice.class);
				result.setDefaultModel("list", list);
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	// 添加客户接待
	@RequestMapping(value = "/consultant_client_reception")
	public ModelAndView consultant_client_reception(ModelMap modelMap, final BaseVo vo, HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, vo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				return result;
			}
		});
		return new ModelAndView("consultant/consultant_client_reception_d", modelMap);
	}

	// 学员查询
	@RequestMapping(value = "/consultant_student_list")
	public ModelAndView consultant_student_list(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, vo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				try {
					String type = request.getParameter("type");
					String btnInvalid = request.getParameter("btnInvalid");
					String key = request.getParameter("key");

					TgClient client = new TgClient();
					TgUser user = UserUtil.getUserFromCookies();
					client.setUsername(user.getUsername());

					if (type != null && !"".equals(type)) {
						if (type.equals("0")) {
							client.setNickname(key);
						} else if (type.equals("1")) {
							client.setStudent(key);
						} else if (type.equals("2")) {
							client.setPhone(key);
						} else if (type.equals("3")) {
							client.setQq(key);
						} else if (type.equals("4")) {
							client.setEmail(key);
						} else if (type.equals("5")) {
							client.setKeyword(key);
						}
					}

					if (btnInvalid != null && btnInvalid.equals("true")) {
						client.setInvalid(0);
					}
					Integer currPage = 1;
					if (vo.getCurrPage() != null && !"".equals(vo.getCurrPage())) {
						currPage = vo.getCurrPage();
					}
					Integer total = clientDao.getClientCountByType(client);
					Page page = PageUtil.createPage(8, currPage, total);
					List<TgClient> list = clientDao.getClientListByType(client, page);

					if (list != null && list.size() > 0) {
						SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
						Gson gson = new Gson();
						JsonValidator json = new JsonValidator();
						for (int i = 0; i < list.size(); i++) {
							if (list.get(i).getPhone() != null && !"".equals(list.get(i).getPhone())) {
								if (list.get(i).getPhone().contains("[{")) {
									List<Phone> ph = gson.fromJson(list.get(i).getPhone(),
											new TypeToken<List<Phone>>() {
											}.getType());
									list.get(i).setPhlist(ph);
									list.get(i).setPhone(list.get(i).getPhlist().get(0).getPhone());
								}
							}

							// 学员特征和资料
							if (list.get(i).getFeature() != null && !"".equals(list.get(i).getFeature())) {
								boolean flag = StringUtil.getHanzi(list.get(i).getFeature());
								if (!flag) {

									byte[] bytes = StringUtil.hexDecode(list.get(i).getFeature());
									String ObjContent = new String(bytes, "UTF-8");
									if (ObjContent != null && !"".equals(ObjContent)) {
										if (ObjContent.contains("\"")) {
											ObjContent = ObjContent.replace('"', ' ');
										}
									}
									list.get(i).setFeature(ObjContent);
								} else {
									if (list.get(i).getFeature().contains("\"")) {
										list.get(i).setFeature(list.get(i).getFeature().replace('"', ' '));
									}
								}
							}

							if (list.get(i).getBirthday() != null) {
								list.get(i).setThday(sdf.format(new Date(list.get(i).getBirthday() * 1000)));
							}
							// 接待表中学员
							String student = list.get(i).getResult();
							if (student != null && !"".equals(student)) {

								Boolean flag = json.validate(student);
								String ObjContent = "";
								if (flag) {
									ObjContent = student;
								} else {
									byte[] bytes = StringUtil.hexDecode(student);
									ObjContent = new String(bytes, "UTF-8");
								}
								if (ObjContent.contains("key")) {
									JSONObject obj = JSONObject.fromObject(ObjContent);
									JSONObject obj2 = null;

									if (ObjContent.contains("\"key\":\"" + list.get(i).getKeyname() + "\"")
											&& obj != null) {
										obj2 = obj.getJSONObject(list.get(i).getKeyname());
										if (!obj2.isNullObject()) {
											// list.get(i).setBool(obj2.getString("testuser"));
										}
									}
								}
							}
						}
					}

					result.setDefaultModel("type", type);
					result.setDefaultModel("key", key);
					result.setDefaultModel("list", list);
					result.setDefaultModel("page", page);
					result.setDefaultModel("client", client);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return result;
			}
		});
		return new ModelAndView("consultant/consultant_student_list", modelMap);
	}

	// 个人专属问卷地址
	@RequestMapping(value = "/consultant_ask_spcode")
	public ModelAndView consultant_ask_spcode(ModelMap modelMap, final LoginVo loginVo, HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, loginVo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				TgUser user = UserUtil.getUserFromCookies();
				JsSpread spread = new JsSpread();
				spread.setUsername(user.getUsername());
				List<JsSpread> list = spreadDao.getSpreadByUsername(spread);
				if (list != null && list.size() > 0) {
					spread = list.get(0);
					if (spread.getCdate() != null) {
						SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
						spread.setCreateDate(sdf.format(new Date(spread.getCdate() * 1000)));
					}
				}
				result.setDefaultModel("spread", spread);
				return result;
			}
		});
		return new ModelAndView("consultant/consultant_ask_spcode", modelMap);
	}

	// 个人业绩周统计分析
	@RequestMapping(value = "/consultant_personal_stat")
	public ModelAndView consultant_personal_stat(ModelMap modelMap, final LoginVo loginVo,
			final HttpServletRequest request, final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, loginVo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String time = request.getParameter("sdate");
				String username = request.getParameter("username");

				SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
				Calendar c_now = new GregorianCalendar();
				Calendar c_begin = new GregorianCalendar();
				Calendar c_end = new GregorianCalendar();
				DateFormatSymbols dfs = new DateFormatSymbols();
				String[] weeks = dfs.getWeekdays();

				// 设置参数，年，月
				String date = "";
				if (time != null && !"".equals(time)) {
					date = time;
				} else {
					date = df.format(new Date());
				}
				result.setDefaultModel("date", date);
				try {
					java.util.Date cDate = df.parse(date);
					c_now.setTime(cDate);
				} catch (Exception e) {
					e.printStackTrace();
				}

				int year = c_now.get(Calendar.YEAR);
				int month = c_now.get(Calendar.MONTH) + 1;
				int[] days = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
				if (year % 4 == 0) {
					days[2] = 29;// 大年
				}
				c_begin.set(year, month - 1, 1); // 月 0-11 天 0-
				c_end.set(year, month - 1, days[month]);

				int count = 1;
				c_end.add(Calendar.DAY_OF_YEAR, 1); // 结束日期下滚一天是为了包含最后一天
				List<MonDate> dataList1 = new ArrayList<MonDate>();
				List<MonDate> dataList2 = new ArrayList<MonDate>();
				List<MonDate> dataList3 = new ArrayList<MonDate>();
				List<MonDate> dataList4 = new ArrayList<MonDate>();
				List<MonDate> dataList5 = new ArrayList<MonDate>();
				List<MonDate> dataList6 = new ArrayList<MonDate>();
				while (c_begin.before(c_end)) {
					if (count == 1) {
						MonDate monDate = new MonDate();
						monDate.setId(count);
						monDate.setTime(new java.sql.Date(c_begin.getTime().getTime()));
						monDate.setWeek(weeks[c_begin.get(Calendar.DAY_OF_WEEK)]);
						dataList1.add(monDate);
					} else if (count == 2) {
						MonDate monDate = new MonDate();
						monDate.setId(count);
						monDate.setTime(new java.sql.Date(c_begin.getTime().getTime()));
						monDate.setWeek(weeks[c_begin.get(Calendar.DAY_OF_WEEK)]);
						dataList2.add(monDate);
					} else if (count == 3) {
						MonDate monDate = new MonDate();
						monDate.setId(count);
						monDate.setTime(new java.sql.Date(c_begin.getTime().getTime()));
						monDate.setWeek(weeks[c_begin.get(Calendar.DAY_OF_WEEK)]);
						dataList3.add(monDate);
					} else if (count == 4) {
						MonDate monDate = new MonDate();
						monDate.setId(count);
						monDate.setTime(new java.sql.Date(c_begin.getTime().getTime()));
						monDate.setWeek(weeks[c_begin.get(Calendar.DAY_OF_WEEK)]);
						dataList4.add(monDate);
					} else if (count == 5) {
						MonDate monDate = new MonDate();
						monDate.setId(count);
						monDate.setTime(new java.sql.Date(c_begin.getTime().getTime()));
						monDate.setWeek(weeks[c_begin.get(Calendar.DAY_OF_WEEK)]);
						dataList5.add(monDate);
					} else if (count == 6) {
						MonDate monDate = new MonDate();
						monDate.setId(count);
						monDate.setTime(new java.sql.Date(c_begin.getTime().getTime()));
						monDate.setWeek(weeks[c_begin.get(Calendar.DAY_OF_WEEK)]);
						dataList6.add(monDate);
					}
					System.out.println("第" + count + "周  日期：" + new java.sql.Date(c_begin.getTime().getTime()) + ", "
							+ weeks[c_begin.get(Calendar.DAY_OF_WEEK)]);
					if (c_begin.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
						count++;
					}
					c_begin.add(Calendar.DAY_OF_YEAR, 1);
				}
				TgUser user = UserUtil.getUserFromCookies();
				if (dataList1 != null && dataList1.size() > 0) {
					Date start = dataList1.get(0).getTime();
					Date end = dataList1.get(dataList1.size() - 1).getTime();

					TgClient client = new TgClient();
					if (user.getUsergroup() == 3) {
						client.setUsername(user.getUsername());
					} else {
						if (username != null && !"".equals(username)) {
							client.setUsername(username);
						} else {
							username = "liuyun";
							client.setUsername("liuyun");
						}

					}
					client.setStartTime(start.getTime() / 1000);
					client.setEndTime(end.getTime() / 1000);
					Integer zoncount = clientDao.getZonClientCount(client);// 客户总量
					Integer wuxiaocount = clientDao.getWuxiaoClientCount(client);// 无效客户数量
					Integer bendicount = clientDao.getBendiClientCount(client);// 本地客户数量
					Integer waidicount = clientDao.getWaidiClientCount(client);// 外地客户数量
					client.setRawusername(user.getUsername());
					Integer zhuanchucount = clientDao.getZhuanchuClientCount(client);// 转出客户数量
					result.setDefaultModel("username", username);
					result.setDefaultModel("start1", start);
					result.setDefaultModel("end1", end);
					result.setDefaultModel("count1", dataList1.get(0).getId());
					result.setDefaultModel("week1", dataList1.get(0).getWeek());
					result.setDefaultModel("zoncount1", zoncount);
					result.setDefaultModel("wuxiaocount1", wuxiaocount);
					result.setDefaultModel("bendicount1", bendicount);
					result.setDefaultModel("waidicount1", waidicount);
					result.setDefaultModel("zhuanchucount1", zhuanchucount);

					// 本月预约数据统计
					TgReserve reserve = new TgReserve();
					reserve.setStart(start.getTime() / 1000);
					reserve.setEnd(end.getTime() / 1000);
					if (user.getUsergroup() == 3) {
						reserve.setUsername(user.getUsername());
					} else {
						if (username != null && !"".equals(username)) {
							reserve.setUsername(username);
						} else {
							username = "liuyun";
							reserve.setUsername("liuyun");
						}

					}
					Integer zonreserve = reserveDao.getZonReserveCountBy(reserve);// 预约数量
					Integer shidao = reserveDao.getShidaoReserveCountBy(reserve);// 实到数量
					Integer feicep = reserveDao.getFeiCepReserveCountBy(reserve);// 非测评数量
					result.setDefaultModel("zonreserve1", zonreserve);
					result.setDefaultModel("shidao1", shidao);
					result.setDefaultModel("feicep1", feicep);
					if (bendicount + zhuanchucount == 0) {
						result.setDefaultModel("yuyuebaifen1", 0);
					} else {
						result.setDefaultModel("yuyuebaifen1", zonreserve / (bendicount + zhuanchucount));
					}

					// 本月接待数据统计
					TgReception reception = new TgReception();
					reception.setStartTime(start.getTime() / 1000);
					reception.setEndTime(end.getTime() / 1000);
					if (user.getUsergroup() == 3) {
						reception.setUsername(user.getUsername());
					} else {
						if (username != null && !"".equals(username)) {
							reception.setUsername(username);
						} else {
							reception.setUsername("liuyun");
						}

					}
					// 汇总当周业绩
					Double sum1 = (double) 0;
					List<TgReception> relist = receptionDao.getMoney(reception);
					List<TgReception> reslist = receptionDao.getMoney1(reception);
					if (relist != null && !"".equals(relist)) {
						for (int i = 0; i < relist.size(); i++) {
							if (relist.get(i).getMoney() != null) {
								sum1 += relist.get(i).getMoney();
							}
						}
					}
					if (reslist != null && !"".equals(reslist)) {
						for (int i = 0; i < reslist.size(); i++) {
							if (reslist.get(i).getMoney1() != null) {
								sum1 += reslist.get(i).getMoney1();
							}
						}
					}

					// 总接待
					Integer zonRece = receptionService.getZonlReceptionCount(reception);

					Integer zonChendan = receptionDao.getDanReceptionCount(reception);
					Integer zonGenz = receptionDao.getReceptionCount(reception);

					result.setDefaultModel("zonRece1", zonRece);
					result.setDefaultModel("sum1", sum1);
					result.setDefaultModel("zonGenz1", zonGenz);
					result.setDefaultModel("zonChendan1", zonChendan);
				}
				if (dataList2 != null && dataList2.size() > 0) {
					Date start = dataList2.get(0).getTime();
					Date end = dataList2.get(dataList2.size() - 1).getTime();

					TgClient client = new TgClient();
					if (user.getUsergroup() == 3) {
						client.setUsername(user.getUsername());
					} else {
						if (username != null && !"".equals(username)) {
							client.setUsername(username);
						} else {
							client.setUsername("liuyun");
						}

					}
					client.setStartTime(start.getTime() / 1000);
					client.setEndTime(end.getTime() / 1000);
					Integer zoncount = clientDao.getZonClientCount(client);// 客户总量
					Integer wuxiaocount = clientDao.getWuxiaoClientCount(client);// 无效客户数量
					Integer bendicount = clientDao.getBendiClientCount(client);// 本地客户数量
					Integer waidicount = clientDao.getWaidiClientCount(client);// 外地客户数量
					client.setRawusername(user.getUsername());
					Integer zhuanchucount = clientDao.getZhuanchuClientCount(client);// 转出客户数量
					result.setDefaultModel("start2", start);
					result.setDefaultModel("end2", end);
					result.setDefaultModel("count2", dataList1.get(0).getId());
					result.setDefaultModel("week2", dataList1.get(0).getWeek());
					result.setDefaultModel("zoncount2", zoncount);
					result.setDefaultModel("wuxiaocount2", wuxiaocount);
					result.setDefaultModel("bendicount2", bendicount);
					result.setDefaultModel("waidicount2", waidicount);
					result.setDefaultModel("zhuanchucount2", zhuanchucount);

					// 本月预约统计
					TgReserve reserve = new TgReserve();
					reserve.setStart(start.getTime() / 1000);
					reserve.setEnd(end.getTime() / 1000);
					if (user.getUsergroup() == 3) {
						reserve.setUsername(user.getUsername());
					} else {
						if (username != null && !"".equals(username)) {
							reserve.setUsername(username);
						} else {
							reserve.setUsername("liuyun");
						}

					}
					Integer zonreserve = reserveDao.getZonReserveCountBy(reserve);// 预约数量
					Integer shidao = reserveDao.getShidaoReserveCountBy(reserve);// 实到数量
					Integer feicep = reserveDao.getFeiCepReserveCountBy(reserve);// 非测评数量
					result.setDefaultModel("zonreserve2", zonreserve);
					result.setDefaultModel("shidao2", shidao);
					result.setDefaultModel("feicep2", feicep);
					if (bendicount + zhuanchucount == 0) {
						result.setDefaultModel("yuyuebaifen2", 0);
					} else {
						result.setDefaultModel("yuyuebaifen2", zonreserve / (bendicount + zhuanchucount));
					}

					// 本月接待数据统计
					TgReception reception = new TgReception();
					reception.setStartTime(start.getTime() / 1000);
					reception.setEndTime(end.getTime() / 1000);
					if (user.getUsergroup() == 3) {
						reception.setUsername(user.getUsername());
					} else {
						if (username != null && !"".equals(username)) {
							reception.setUsername(username);
						} else {
							reception.setUsername("liuyun");
						}

					}

					// 汇总当周业绩
					Double sum2 = (double) 0;
					List<TgReception> relist = receptionDao.getMoney(reception);
					List<TgReception> reslist = receptionDao.getMoney1(reception);
					if (relist != null && !"".equals(relist)) {
						for (int i = 0; i < relist.size(); i++) {
							if (relist.get(i).getMoney() != null) {
								sum2 += relist.get(i).getMoney();
							}
						}
					}
					if (reslist != null && !"".equals(reslist)) {
						for (int i = 0; i < reslist.size(); i++) {
							if (reslist.get(i).getMoney1() != null) {
								sum2 += reslist.get(i).getMoney1();
							}
						}
					}

					// 总接待
					Integer zonRece = receptionService.getZonlReceptionCount(reception);
					Integer zonChendan = receptionDao.getDanReceptionCount(reception);
					Integer zonGenz = receptionDao.getReceptionCount(reception);
					result.setDefaultModel("zonRece2", zonRece);
					result.setDefaultModel("zonGenz2", zonGenz);
					result.setDefaultModel("sum2", sum2);
					result.setDefaultModel("zonChendan2", zonChendan);
				}
				if (dataList3 != null && dataList3.size() > 0) {
					Date start = dataList3.get(0).getTime();
					Date end = dataList3.get(dataList3.size() - 1).getTime();

					TgClient client = new TgClient();
					if (user.getUsergroup() == 3) {
						client.setUsername(user.getUsername());
					} else {
						if (username != null && !"".equals(username)) {
							client.setUsername(username);
						} else {
							client.setUsername("liuyun");
						}

					}
					client.setStartTime(start.getTime() / 1000);
					client.setEndTime(end.getTime() / 1000);
					Integer zoncount = clientDao.getZonClientCount(client);// 客户总量
					Integer wuxiaocount = clientDao.getWuxiaoClientCount(client);// 无效客户数量
					Integer bendicount = clientDao.getBendiClientCount(client);// 本地客户数量
					Integer waidicount = clientDao.getWaidiClientCount(client);// 外地客户数量
					client.setRawusername(user.getUsername());
					Integer zhuanchucount = clientDao.getZhuanchuClientCount(client);// 转出客户数量
					result.setDefaultModel("start3", start);
					result.setDefaultModel("end3", end);
					result.setDefaultModel("count3", dataList1.get(0).getId());
					result.setDefaultModel("week3", dataList1.get(0).getWeek());
					result.setDefaultModel("zoncount3", zoncount);
					result.setDefaultModel("wuxiaocount3", wuxiaocount);
					result.setDefaultModel("bendicount3", bendicount);
					result.setDefaultModel("waidicount3", waidicount);
					result.setDefaultModel("zhuanchucount3", zhuanchucount);

					// 本月预约统计
					TgReserve reserve = new TgReserve();
					reserve.setStart(start.getTime() / 1000);
					reserve.setEnd(end.getTime() / 1000);
					if (user.getUsergroup() == 3) {
						reserve.setUsername(user.getUsername());
					} else {
						if (username != null && !"".equals(username)) {
							reserve.setUsername(username);
						} else {
							reserve.setUsername("liuyun");
						}

					}
					Integer zonreserve = reserveDao.getZonReserveCountBy(reserve);// 预约数量
					Integer shidao = reserveDao.getShidaoReserveCountBy(reserve);// 实到数量
					Integer feicep = reserveDao.getFeiCepReserveCountBy(reserve);// 非测评数量
					result.setDefaultModel("zonreserve3", zonreserve);
					result.setDefaultModel("shidao3", shidao);
					result.setDefaultModel("feicep3", feicep);
					if (bendicount + zhuanchucount == 0) {
						result.setDefaultModel("yuyuebaifen3", 0);
					} else {
						result.setDefaultModel("yuyuebaifen3", zonreserve / (bendicount + zhuanchucount));
					}

					// 本月接待数据统计
					TgReception reception = new TgReception();
					reception.setStartTime(start.getTime() / 1000);
					reception.setEndTime(end.getTime() / 1000);
					if (user.getUsergroup() == 3) {
						reception.setUsername(user.getUsername());
					} else {
						if (username != null && !"".equals(username)) {
							reception.setUsername(username);
						} else {
							reception.setUsername("liuyun");
						}

					}

					// 汇总当周业绩
					Double sum3 = (double) 0;
					List<TgReception> relist = receptionDao.getMoney(reception);
					List<TgReception> reslist = receptionDao.getMoney1(reception);
					if (relist != null && !"".equals(relist)) {
						for (int i = 0; i < relist.size(); i++) {
							if (relist.get(i).getMoney() != null) {
								sum3 += relist.get(i).getMoney();
							}
						}
					}
					if (reslist != null && !"".equals(reslist)) {
						for (int i = 0; i < reslist.size(); i++) {
							if (reslist.get(i).getMoney1() != null) {
								sum3 += reslist.get(i).getMoney1();
							}
						}
					}

					// 总接待
					Integer zonRece = receptionService.getZonlReceptionCount(reception);
					Integer zonChendan = receptionDao.getDanReceptionCount(reception);
					Integer zonGenz = receptionDao.getReceptionCount(reception);
					result.setDefaultModel("zonRece3", zonRece);
					result.setDefaultModel("sum3", sum3);
					result.setDefaultModel("zonGenz3", zonGenz);
					result.setDefaultModel("zonChendan3", zonChendan);
				}
				if (dataList4 != null && dataList4.size() > 0) {
					Date start = dataList4.get(0).getTime();
					Date end = dataList4.get(dataList4.size() - 1).getTime();

					TgClient client = new TgClient();
					if (user.getUsergroup() == 3) {
						client.setUsername(user.getUsername());
					} else {
						if (username != null && !"".equals(username)) {
							client.setUsername(username);
						} else {
							client.setUsername("liuyun");
						}

					}
					client.setStartTime(start.getTime() / 1000);
					client.setEndTime(end.getTime() / 1000);
					Integer zoncount = clientDao.getZonClientCount(client);// 客户总量
					Integer wuxiaocount = clientDao.getWuxiaoClientCount(client);// 无效客户数量
					Integer bendicount = clientDao.getBendiClientCount(client);// 本地客户数量
					Integer waidicount = clientDao.getWaidiClientCount(client);// 外地客户数量
					client.setRawusername(user.getUsername());
					Integer zhuanchucount = clientDao.getZhuanchuClientCount(client);// 转出客户数量
					result.setDefaultModel("start4", start);
					result.setDefaultModel("end4", end);
					result.setDefaultModel("count4", dataList1.get(0).getId());
					result.setDefaultModel("week4", dataList1.get(0).getWeek());
					result.setDefaultModel("zoncount4", zoncount);
					result.setDefaultModel("wuxiaocount4", wuxiaocount);
					result.setDefaultModel("bendicount4", bendicount);
					result.setDefaultModel("waidicount4", waidicount);
					result.setDefaultModel("zhuanchucount4", zhuanchucount);

					// 本月预约统计
					TgReserve reserve = new TgReserve();
					reserve.setStart(start.getTime() / 1000);
					reserve.setEnd(end.getTime() / 1000);
					if (user.getUsergroup() == 3) {
						reserve.setUsername(user.getUsername());
					} else {
						if (username != null && !"".equals(username)) {
							reserve.setUsername(username);
						} else {
							reserve.setUsername("liuyun");
						}

					}
					Integer zonreserve = reserveDao.getZonReserveCountBy(reserve);// 预约数量
					Integer shidao = reserveDao.getShidaoReserveCountBy(reserve);// 实到数量
					Integer feicep = reserveDao.getFeiCepReserveCountBy(reserve);// 非测评数量
					result.setDefaultModel("zonreserve4", zonreserve);
					result.setDefaultModel("shidao4", shidao);
					result.setDefaultModel("feicep4", feicep);
					if (bendicount + zhuanchucount == 0) {
						result.setDefaultModel("yuyuebaifen4", 0);
					} else {
						result.setDefaultModel("yuyuebaifen4", zonreserve / (bendicount + zhuanchucount));
					}

					// 本月接待数据统计
					TgReception reception = new TgReception();
					reception.setStartTime(start.getTime() / 1000);
					reception.setEndTime(end.getTime() / 1000);
					if (user.getUsergroup() == 3) {
						reception.setUsername(user.getUsername());
					} else {
						if (username != null && !"".equals(username)) {
							reception.setUsername(username);
						} else {
							reception.setUsername("liuyun");
						}

					}

					// 汇总当周业绩
					Double sum4 = (double) 0;
					List<TgReception> relist = receptionDao.getMoney(reception);
					List<TgReception> reslist = receptionDao.getMoney1(reception);
					if (relist != null && !"".equals(relist)) {
						for (int i = 0; i < relist.size(); i++) {
							if (relist.get(i).getMoney() != null) {
								sum4 += relist.get(i).getMoney();
							}
						}
					}
					if (reslist != null && !"".equals(reslist)) {
						for (int i = 0; i < reslist.size(); i++) {
							if (reslist.get(i).getMoney1() != null) {
								sum4 += reslist.get(i).getMoney1();
							}
						}
					}

					// 总接待
					Integer zonRece = receptionService.getZonlReceptionCount(reception);
					Integer zonChendan = receptionDao.getDanReceptionCount(reception);
					Integer zonGenz = receptionDao.getReceptionCount(reception);
					result.setDefaultModel("zonRece4", zonRece);
					result.setDefaultModel("zonGenz4", zonGenz);
					result.setDefaultModel("sum4", sum4);
					result.setDefaultModel("zonChendan4", zonChendan);
				}
				if (dataList5 != null && dataList5.size() > 0) {
					Date start = dataList5.get(0).getTime();
					Date end = dataList5.get(dataList5.size() - 1).getTime();

					TgClient client = new TgClient();
					if (user.getUsergroup() == 3) {
						client.setUsername(user.getUsername());
					} else {
						if (username != null && !"".equals(username)) {
							client.setUsername(username);
						} else {
							client.setUsername("liuyun");
						}

					}
					client.setStartTime(start.getTime() / 1000);
					client.setEndTime(end.getTime() / 1000);
					Integer zoncount = clientDao.getZonClientCount(client);// 客户总量
					Integer wuxiaocount = clientDao.getWuxiaoClientCount(client);// 无效客户数量
					Integer bendicount = clientDao.getBendiClientCount(client);// 本地客户数量
					Integer waidicount = clientDao.getWaidiClientCount(client);// 外地客户数量
					client.setRawusername(user.getUsername());
					Integer zhuanchucount = clientDao.getZhuanchuClientCount(client);// 转出客户数量
					result.setDefaultModel("start5", start);
					result.setDefaultModel("end5", end);
					result.setDefaultModel("count5", dataList1.get(0).getId());
					result.setDefaultModel("week5", dataList1.get(0).getWeek());
					result.setDefaultModel("zoncount5", zoncount);
					result.setDefaultModel("wuxiaocount5", wuxiaocount);
					result.setDefaultModel("bendicount5", bendicount);
					result.setDefaultModel("waidicount5", waidicount);
					result.setDefaultModel("zhuanchucount5", zhuanchucount);

					// 本月预约统计
					TgReserve reserve = new TgReserve();
					reserve.setStart(start.getTime() / 1000);
					reserve.setEnd(end.getTime() / 1000);
					if (user.getUsergroup() == 3) {
						reserve.setUsername(user.getUsername());
					} else {
						if (username != null && !"".equals(username)) {
							reserve.setUsername(username);
						} else {
							reserve.setUsername("liuyun");
						}

					}
					Integer zonreserve = reserveDao.getZonReserveCountBy(reserve);// 预约数量
					Integer shidao = reserveDao.getShidaoReserveCountBy(reserve);// 实到数量
					Integer feicep = reserveDao.getFeiCepReserveCountBy(reserve);// 非测评数量
					result.setDefaultModel("zonreserve5", zonreserve);
					result.setDefaultModel("shidao5", shidao);
					result.setDefaultModel("feicep5", feicep);
					if (bendicount + zhuanchucount == 0) {
						result.setDefaultModel("yuyuebaifen5", 0);
					} else {
						result.setDefaultModel("yuyuebaifen5", zonreserve / (bendicount + zhuanchucount));
					}

					// 本月接待数据统计
					TgReception reception = new TgReception();
					reception.setStartTime(start.getTime() / 1000);
					reception.setEndTime(end.getTime() / 1000);
					if (user.getUsergroup() == 3) {
						reception.setUsername(user.getUsername());
					} else {
						if (username != null && !"".equals(username)) {
							reception.setUsername(username);
						} else {
							reception.setUsername("liuyun");
						}

					}
					// 汇总当周业绩
					Double sum5 = (double) 0;
					List<TgReception> relist = receptionDao.getMoney(reception);
					List<TgReception> reslist = receptionDao.getMoney1(reception);
					if (relist != null && !"".equals(relist)) {
						for (int i = 0; i < relist.size(); i++) {
							if (relist.get(i).getMoney() != null) {
								sum5 += relist.get(i).getMoney();
							}
						}
					}
					if (reslist != null && !"".equals(reslist)) {
						for (int i = 0; i < reslist.size(); i++) {
							if (reslist.get(i).getMoney1() != null) {
								sum5 += reslist.get(i).getMoney1();
							}
						}
					}

					// 总接待
					Integer zonRece = receptionService.getZonlReceptionCount(reception);
					Integer zonChendan = receptionDao.getDanReceptionCount(reception);
					Integer zonGenz = receptionDao.getReceptionCount(reception);
					result.setDefaultModel("zonRece5", zonRece);
					result.setDefaultModel("zonGenz5", zonGenz);
					result.setDefaultModel("sum5", sum5);
					result.setDefaultModel("zonChendan5", zonChendan);
				}
				if (dataList6 != null && dataList6.size() > 0) {
					Date start = dataList6.get(0).getTime();
					Date end = dataList6.get(dataList6.size() - 1).getTime();

					TgClient client = new TgClient();
					if (user.getUsergroup() == 3) {
						client.setUsername(user.getUsername());
					} else {
						if (username != null && !"".equals(username)) {
							client.setUsername(username);
						} else {
							client.setUsername("liuyun");
						}

					}
					client.setStartTime(start.getTime() / 1000);
					client.setEndTime(end.getTime() / 1000);
					Integer zoncount = clientDao.getZonClientCount(client);// 客户总量
					Integer wuxiaocount = clientDao.getWuxiaoClientCount(client);// 无效客户数量
					Integer bendicount = clientDao.getBendiClientCount(client);// 本地客户数量
					Integer waidicount = clientDao.getWaidiClientCount(client);// 外地客户数量
					client.setRawusername(user.getUsername());
					Integer zhuanchucount = clientDao.getZhuanchuClientCount(client);// 转出客户数量
					result.setDefaultModel("start6", start);
					result.setDefaultModel("end6", end);
					result.setDefaultModel("count6", dataList1.get(0).getId());
					result.setDefaultModel("week6", dataList1.get(0).getWeek());
					result.setDefaultModel("zoncount6", zoncount);
					result.setDefaultModel("wuxiaocount6", wuxiaocount);
					result.setDefaultModel("bendicount6", bendicount);
					result.setDefaultModel("waidicount6", waidicount);
					result.setDefaultModel("zhuanchucount6", zhuanchucount);

					// 本月预约统计
					TgReserve reserve = new TgReserve();
					reserve.setStart(start.getTime() / 1000);
					reserve.setEnd(end.getTime() / 1000);
					if (user.getUsergroup() == 3) {
						reserve.setUsername(user.getUsername());
					} else {
						if (username != null && !"".equals(username)) {
							reserve.setUsername(username);
						} else {
							reserve.setUsername("liuyun");
						}

					}
					Integer zonreserve = reserveDao.getZonReserveCountBy(reserve);// 预约数量
					Integer shidao = reserveDao.getShidaoReserveCountBy(reserve);// 实到数量
					Integer feicep = reserveDao.getFeiCepReserveCountBy(reserve);// 非测评数量
					result.setDefaultModel("zonreserve6", zonreserve);
					result.setDefaultModel("shidao6", shidao);
					result.setDefaultModel("feicep6", feicep);
					if (bendicount + zhuanchucount == 0) {
						result.setDefaultModel("yuyuebaifen6", 0);
					} else {
						result.setDefaultModel("yuyuebaifen6", zonreserve / (bendicount + zhuanchucount));
					}

					// 本月接待数据统计
					TgReception reception = new TgReception();
					reception.setStartTime(start.getTime() / 1000);
					reception.setEndTime(end.getTime() / 1000);
					if (user.getUsergroup() == 3) {
						reception.setUsername(user.getUsername());
					} else {
						if (username != null && !"".equals(username)) {
							reception.setUsername(username);
						} else {
							reception.setUsername("liuyun");
						}

					}

					// 汇总当周业绩
					Double sum6 = (double) 0;
					List<TgReception> relist = receptionDao.getMoney(reception);
					List<TgReception> reslist = receptionDao.getMoney1(reception);
					if (relist != null && !"".equals(relist)) {
						for (int i = 0; i < relist.size(); i++) {
							if (relist.get(i).getMoney() != null) {
								sum6 += relist.get(i).getMoney();
							}
						}
					}
					if (reslist != null && !"".equals(reslist)) {
						for (int i = 0; i < reslist.size(); i++) {
							if (reslist.get(i).getMoney1() != null) {
								sum6 += reslist.get(i).getMoney1();
							}
						}
					}

					// 总接待
					Integer zonRece = receptionService.getZonlReceptionCount(reception);
					Integer zonChendan = receptionDao.getDanReceptionCount(reception);
					Integer zonGenz = receptionDao.getReceptionCount(reception);
					result.setDefaultModel("zonRece6", zonRece);
					result.setDefaultModel("sum6", sum6);
					result.setDefaultModel("zonGenz6", zonGenz);
					result.setDefaultModel("zonChendan6", zonChendan);
				}

				TgUserinfo users = new TgUserinfo();
				users.setJob("课程顾问");
				List<TgUserinfo> uList = userinfoDao.getUserInfoByUserInfo(users);
				result.setDefaultModel("uList", uList);

				System.out.println("共计（跨越）：" + (count - 1) + "周");
				return result;
			}
		});
		return new ModelAndView("consultant/consultant_personal_stat", modelMap);
	}

	// 个人业绩月统计
	@RequestMapping(value = "/consultant_personal_month_stat")
	public ModelAndView consultant_personal_month_stat(ModelMap modelMap, final LoginVo loginVo,
			final HttpServletRequest request, final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, loginVo, new Biz() {
			@SuppressWarnings("deprecation")
			public Result process() {
				Result result = new ResultSupport(true);
				String startTime = request.getParameter("sdate");
				String endTime = request.getParameter("edate");

				SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
				String sdate = "";
				String edate = "";
				try {
					Date start = null;
					Date end = null;
					if (startTime != null && !"".equals(startTime)) {
						start = df.parse(startTime);
						sdate = df.format(start);
					} else {
						start = DateUtil.getFirstDayCurrMonth();
						sdate = df.format(start);
					}
					result.setDefaultModel("sdate", sdate);

					if (endTime != null && !"".equals(endTime)) {
						Calendar ca = Calendar.getInstance();
						ca.setTime(df.parse(endTime));
						ca.set(Calendar.DATE, 1);
						ca.add(Calendar.MONTH, 1);
						ca.add(Calendar.DATE, -1);
						end = ca.getTime();
						edate = df.format(end);
					} else {
						Calendar ca = Calendar.getInstance();
						ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));
						end = ca.getTime();
						edate = df.format(end);
					}
					result.setDefaultModel("edate", edate);

					TgUser user = UserUtil.getUserFromCookies();

					TgClient client = new TgClient();
					client.setStartTime(start.getTime() / 1000);
					client.setEndTime(end.getTime() / 1000);
					if (user.getUsergroup() == 3) {
						client.setUsername(user.getUsername());
					}
					Integer zoncount = clientDao.getZonClientCount(client);// 客户总量
					Integer wuxiaocount = clientDao.getWuxiaoClientCount(client);// 无效客户数量
					Integer bendicount = clientDao.getBendiClientCount(client);// 本地客户数量
					Integer waidicount = clientDao.getWaidiClientCount(client);// 外地客户数量
					client.setRawusername(user.getUsername());
					Integer zhuanchucount = clientDao.getZhuanchuClientCount(client);// 转出客户数量
					result.setDefaultModel("start", start);
					result.setDefaultModel("end", end);
					result.setDefaultModel("zoncount", zoncount);
					result.setDefaultModel("wuxiaocount", wuxiaocount);
					result.setDefaultModel("bendicount", bendicount);
					result.setDefaultModel("waidicount", waidicount);
					result.setDefaultModel("zhuanchucount", zhuanchucount);

					// 本月预约数据统计
					TgReserve reserve = new TgReserve();
					reserve.setStart(start.getTime() / 1000);
					reserve.setEnd(end.getTime() / 1000);
					if (user.getUsergroup() == 3) {
						reserve.setUsername(user.getUsername());
					}
					Integer zonreserve = reserveDao.getZonReserveCountBy(reserve);// 预约数量
					Integer shidao = reserveDao.getShidaoReserveCountBy(reserve);// 实到数量
					Integer feicep = reserveDao.getFeiCepReserveCountBy(reserve);// 非测评数量
					result.setDefaultModel("zonreserve", zonreserve);
					result.setDefaultModel("shidao", shidao);
					result.setDefaultModel("feicep", feicep);
					if (zonreserve != 0) {
						float scale = (float) shidao / zonreserve;
						DecimalFormat fnum = new DecimalFormat("##0.00%");
						String yuyuebaifen = fnum.format(scale);
						result.setDefaultModel("yuyuebaifen", yuyuebaifen);
					} else {
						result.setDefaultModel("yuyuebaifen", 0);

					}

					// 本月接待数据统计
					TgReception reception = new TgReception();
					reception.setStartTime(start.getTime() / 1000);
					reception.setEndTime(end.getTime() / 1000);

					if (user.getUsergroup() == 3) {
						reception.setUsername(user.getUsername());
					}

					// 总接待
					Integer zonRece = receptionService.getZonlReceptionCount(reception);
					Integer zonChendan = receptionDao.getDanReceptionCount(reception);
					Double sum = (double) 0;
					List<TgReception> relist = receptionDao.getMoney(reception);
					List<TgReception> reslist = receptionDao.getMoney1(reception);
					if (relist != null && !"".equals(relist)) {
						for (int i = 0; i < relist.size(); i++) {
							if (relist.get(i).getMoney() != null) {
								sum += relist.get(i).getMoney();
							}
						}
					}
					if (reslist != null && !"".equals(reslist)) {
						for (int i = 0; i < reslist.size(); i++) {
							if (reslist.get(i).getMoney1() != null) {
								sum += reslist.get(i).getMoney1();
							}
						}
					}

					if (zonChendan != 0) {
						float scale = (float) zonChendan / zonRece;
						DecimalFormat fnum = new DecimalFormat("##0.00%");
						String totrate = fnum.format(scale);
						result.setDefaultModel("totrate", totrate);
					} else {
						result.setDefaultModel("totrate", 0);

					}

					Integer zonGenz = receptionDao.getReceptionCount(reception);
					result.setDefaultModel("zonRece", zonRece);
					result.setDefaultModel("zonGenz", zonGenz);
					result.setDefaultModel("sum", sum);
					result.setDefaultModel("zonChendan", zonChendan);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return result;
			}
		});
		return new ModelAndView("consultant/consultant_personal_month_stat", modelMap);
	}

	// 预约信息时间判断
	@RequestMapping(value = "/selectdate")
	public ModelAndView selectdate(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String date = request.getParameter("date");
				String time = request.getParameter("time");

				String dates = date + " " + time;
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
				try {
					if (dates != null && !"".equals(dates)) {
						Long d = sdf.parse(dates).getTime();
						Long tody = new Date().getTime();
						if (d < tody) {
							result.setDefaultModel("msg", "0");
						}
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	// 添加或编辑预约信息
	@RequestMapping(value = "/consultant_client_reserve_form")
	public ModelAndView consultant_client_reserve_form(ModelMap modelMap, final LoginVo loginVo,
			final HttpServletRequest request, final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, loginVo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String keyname = request.getParameter("keyname");
				String date1 = request.getParameter("date");
				String date = date1.substring(18, 28);
				String time = request.getParameter("time");
				String region = request.getParameter("region");
				String username = "";
				String usname = "";
				String region_u = "";

				TgUser u = UserUtil.getUserFromCookies();
				username = u.getNickname();
				String reclient = "";
				String[] restu = null;
				TgReserve reserve = new TgReserve();
				if (keyname != null && !"".equals(keyname)) {
					reserve.setKeyname(keyname);
				} else {
					List<TgSource> souList = sourceDao.findAll(TgSource.class);
					List<TgCategory> cateList = categoryDao.findAll(TgCategory.class);
					List<TgOffice> offList = tgOfficeDao.findAll(TgOffice.class);

					result.setDefaultModel("offList", offList);
					result.setDefaultModel("souList", souList);
					result.setDefaultModel("cateList", cateList);
					result.setDefaultModel("date", date);
					result.setDefaultModel("region", region);
					result.setDefaultModel("username", username);
					result.setDefaultModel("time", time);
					return result;
				}
				List<TgReserve> resList = reserveDao.findByExample(reserve);
				if (resList != null && resList.size() > 0) {
					reserve = resList.get(0);
					reclient = reserve.getClient();
					region_u = reserve.getRegion();
					if (reserve.getStudent().contains(",")) {
						restu = reserve.getStudent().split(",");
					}
					username = reserve.getUsername();
					if (reserve != null && !"".equals(reserve)) {
						// 发起预约人
						TgUserinfo user = new TgUserinfo();
						user.setUsername(reserve.getUsername());
						List<TgUserinfo> userList = userinfoDao.findByExample(user);
						if (userList != null && userList.size() > 0) {
							reserve.setUsername(userList.get(0).getNickname());// 发起预约人
						}
						usname = reserve.getReception_u();
						// 接待老师
						TgUserinfo user2 = new TgUserinfo();
						user2.setUsername(reserve.getReception_u());
						List<TgUserinfo> userList2 = userinfoDao.findByExample(user2);
						if (userList2 != null && userList2.size() > 0) {
							reserve.setReception_u(userList2.get(0).getNickname());
						}
						// System.out.println(reserve.getState2());
						// System.out.println(reserve.getYuanyin());
						// 备注内容转换
						if (reserve.getRemark() != null && !"".equals(reserve.getRemark())) {
							boolean flag = StringUtil.getHanzi(reserve.getRemark());
							if (!flag) {
								try {
									byte[] bytes = StringUtil.hexDecode(reserve.getRemark());
									String ObjContent = new String(bytes, "UTF-8");
									reserve.setRemark(ObjContent);
								} catch (Exception e) {
									e.printStackTrace();
								}
							} else {
								if (reserve.getRemark().contains("备注:")) {
									reserve.setRemark(reserve.getRemark().replace("备注:", ""));
								}
							}
						}

					}
				}

				TgClient client = new TgClient();
				client.setKeyname(reclient);
				List<TgClient> list = clientDao.getClientByKeyname(client);
				if (list != null && list.size() > 0) {
					client = list.get(0);
					if (client.getDescs() != null && !"".equals(client.getDescs())) {
						boolean flag = StringUtil.getHanzi(client.getDescs());
						if (!flag) {
							try {
								byte[] bytes = StringUtil.hexDecode(client.getDescs());
								String ObjContent = new String(bytes, "UTF-8");
								client.setDescs(ObjContent);
							} catch (Exception e) {
								e.printStackTrace();
							}
						}
					}
					List<Phone> ph = null;
					if (client.getPhone() != null && !"".equals(client.getPhone())) {
						if (client.getPhone().contains("[{")) {
							Gson gson = new Gson();
							ph = gson.fromJson(client.getPhone(), new TypeToken<List<Phone>>() {
							}.getType());
						}
					}

					if (client.getPhone() != null && !"".equals(client.getPhone())) {
						if (u.getUsername() != null && !"".equals(u.getUsername())) {
							String u_region = u.getRegion();
							String region_temp = u.getRegion_temp();
							if (u_region != null && !"".equals(u_region)
									|| region_temp != null && !"".equals(region_temp)) {
								if (u_region.equals(region_u)) {
									client.setPhlist(ph);
									client.setPhone(client.getPhone());
								} else if (region_temp != null && !"".equals(region_temp)) {
									if (region_temp.contains(region_u)) {
										client.setPhlist(ph);
										client.setPhone(client.getPhone());
									} else {
										client.setPhone("<span class=\"caption\">禁止查看</span>");
									}
								} else {
									client.setPhone("<span class=\"caption\">禁止查看</span>");
								}
							}
						}
					}

					String quests = client.getQuests();
					if (quests != null && !"".equals(quests) && !"[]".equals(quests)) {
						String ObjContent = "";
						boolean flag = StringUtil.getHanzi(quests);
						if (!flag) {
							try {
								byte[] bytes = StringUtil.hexDecode(quests);
								ObjContent = new String(bytes, "UTF-8");
							} catch (Exception e) {
								e.printStackTrace();
							}
						} else {
							ObjContent = quests;
						}

						try {
							JSONArray array = new JSONArray(ObjContent);
							Gson gson = new Gson();
							List<Quests> quesList = new ArrayList<Quests>();
							if (array != null && !"".equals(array)) {
								for (int i = 0; i < array.length(); i++) {
									Quests quest = new Quests();
									quest = gson.fromJson(array.get(i).toString(), Quests.class);
									quesList.add(quest);
								}
								client.setQueList(quesList);
							}
						} catch (JSONException e) {
							e.printStackTrace();
						}

					}
				}

				TgStudent student = new TgStudent();
				student.setPkey(reclient);
				List<TgStudent> stuList = studentDao.findByExample(student);
				if (stuList != null && stuList.size() > 0) {
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
					for (TgStudent stu : stuList) {
						// 生日转换
						if (stu.getBirthday() != null && !"".equals(stu.getBirthday())) {
							String birthdays = sdf.format(new Date(stu.getBirthday() * 1000));
							stu.setBirthdays(birthdays);
						}
						// 备注文字解密
						if (stu.getFeature() != null && !"".equals(stu.getFeature())) {
							boolean flag = StringUtil.getHanzi(stu.getFeature());
							if (!flag) {
								try {
									byte[] bytes = StringUtil.hexDecode(stu.getFeature());
									String ObjContent = new String(bytes, "UTF-8");
									stu.setFeature(ObjContent);
								} catch (Exception e) {
									e.printStackTrace();
								}
							}
						}

					}
				}
				TgTracking track = new TgTracking();
				track.setClient(reclient);
				List<TgTracking> traList = trackingDao.findByExample(track);
				TgState state = new TgState();
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				if (traList != null && traList.size() > 0) {
					for (TgTracking tra : traList) {
						// 状态
						if (tra.getState() != null && !"".equals(tra.getState())) {
							if (tra.getState().contains(",")) {
								String[] stat = tra.getState().split(",");
								if (stat.getClass().isArray()) {
									String stats = "";
									for (int i = 0; i < stat.length; i++) {
										state.setKeyname(stat[i]);
										List<TgState> stateList = stateDao.findByExample(state);
										if (stateList != null && stateList.size() > 0) {
											stats = stats + stateList.get(0).getName() + ",";
										}
									}
									String[] sta = stats.split(",");
									List<State> staList = new ArrayList<State>();
									List<String> person = new ArrayList<>(Arrays.asList(sta));
									for (int j = 0; j < person.size(); j++) {
										State states = new State();
										states.setState(person.get(j));
										staList.add(states);
									}
									tra.setSlist(staList);
								}
							} else {
								state.setKeyname(tra.getState());
								List<TgState> stateList = stateDao.findByExample(state);
								if (stateList != null && stateList.size() > 0) {
									tra.setState(stateList.get(0).getName());
								}
							}
						}

						// 备注内容
						if (tra.getRemark() != null && !"".equals(tra.getRemark())) {
							if (StringUtil.isNum(tra.getRemark())) {
								tra.setRemark(tra.getRemark());
							} else {
								boolean flag = StringUtil.getHanzi(tra.getRemark());
								if (!flag) {
									try {
										byte[] bytes = StringUtil.hexDecode(tra.getRemark());
										String ObjContent = new String(bytes, "UTF-8");
										tra.setRemark(ObjContent);
									} catch (Exception e) {
										e.printStackTrace();
									}
								}
							}
						}

						// 负责人
						TgUserinfo user = new TgUserinfo();
						user.setUsername(tra.getUsername());
						List<TgUserinfo> ulist = userinfoDao.findByExample(user);
						if (ulist != null && ulist.size() > 0) {
							tra.setNickname(ulist.get(0).getNickname());
						}
						// 时间转换
						if (tra.getCdate() != null && !"".equals(tra.getCdate())) {
							String createTime = sdf.format(new Date(tra.getCdate() * 1000));
							tra.setCreateTime(createTime);
						}

					}
				}
				TgUserinfo userinfo = new TgUserinfo();
				userinfo.setJob("课程顾问");
				List<TgUserinfo> uList = userinfoDao.getUserInfoByUserInfo(userinfo);

				TgUserinfo user_info1 = new TgUserinfo();
				user_info1.setJob("在线课程顾问");

				List<TgUserinfo> uLists = userinfoDao.getUserInfoByUserInfo(user_info1);

				List<TgSource> souList = sourceDao.findAll(TgSource.class);
				List<TgCategory> cateList = categoryDao.findAll(TgCategory.class);
				List<TgOffice> offList = tgOfficeDao.findAll(TgOffice.class);

				// 获取修改人
				if (MathUtil.isNotEmpty(reserve.getUpdate_user())) {
					List<String> upUserStr = new ArrayList<>();
					String[] upUser = reserve.getUpdate_user().split(",");
					for (String str : upUser) {
						upUserStr.add(str);
					}
					result.setDefaultModel("upUserStr", upUserStr);
				}

				result.setDefaultModel("keyname", keyname);
				result.setDefaultModel("reserve", reserve);
				result.setDefaultModel("offList", offList);
				result.setDefaultModel("traList", traList);
				result.setDefaultModel("souList", souList);
				result.setDefaultModel("cateList", cateList);
				result.setDefaultModel("client", client);
				result.setDefaultModel("stuList", stuList);
				result.setDefaultModel("date", date);
				result.setDefaultModel("usname", usname);
				result.setDefaultModel("time", time);
				result.setDefaultModel("restu", restu);
				result.setDefaultModel("uList", uList);
				result.setDefaultModel("uLists", uLists);
				return result;
			}
		});
		return new ModelAndView("consultant/consultant_client_reserve_form", modelMap);

	}

	// 异步获取客户资源列表--只有客户资料
	@RequestMapping(value = "/getclientbytype")
	public ModelAndView getClientByType(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String condition = request.getParameter("condition");

				String nickname = "";
				String phone = "";
				String email = "";

				if (condition != null && !"".equals(condition)) {
					boolean flag = StringUtil.isNum(condition);
					if (flag) {
						phone = condition;
					} else {
						nickname = condition;
					}
				}
				if (condition.contains("@")) {
					email = condition;
				}

				TgUser user = UserUtil.getUserFromCookies();
				TgClient client = new TgClient();

				client.setUsername(user.getUsername());

				if (nickname != null && !"".equals(nickname) && !"null".equals(nickname)) {
					client.setNickname(nickname);
				}

				if (phone != null && !"".equals(phone)) {
					client.setPhone(phone);
				}

				if (email != null && !"".equals(email)) {
					client.setEmail(email);
				}

				List<TgClient> list = clientDao.getClientByPhone(client);
				Gson gson = new Gson();

				for (TgClient c : list) {
					if (c.getPhone() != null && !"".equals(c.getPhone())) {
						if (c.getPhone().contains("[{")) {
							List<Phone> ph = gson.fromJson(c.getPhone(), new TypeToken<List<Phone>>() {
							}.getType());
							c.setPhlist(ph);
						}
					}
				}

				result.setDefaultModel("list", list);
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	// 异步获取客户资源列表--客户所有数据（客户资料，学生详情，跟踪记录）
	@RequestMapping(value = "/getclientall")
	public ModelAndView getclientall(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String id = request.getParameter("id");
				String clients = request.getParameter("client");
				String reskey = request.getParameter("keyname");
				String resdate = request.getParameter("resdate");

				TgClient client = new TgClient();
				if (id != null && !"".equals(id)) {
					client.setId(Long.valueOf(id));
				}
				if (clients != null && !"".equals(clients)) {
					client.setKeyname(clients);
				}

				List<TgClient> list = clientDao.getClientByKeyname(client);
				if (list != null && list.size() > 0) {
					client = list.get(0);
					if (client.getDescs() != null && !"".equals(client.getDescs())) {
						boolean flag = StringUtil.getHanzi(client.getDescs());
						if (!flag) {
							try {
								byte[] bytes = StringUtil.hexDecode(client.getDescs());
								String ObjContent = new String(bytes, "UTF-8");
								client.setDescs(ObjContent);
							} catch (Exception e) {
								e.printStackTrace();
							}
						}
					}

					String phone = client.getPhone();
					if (phone != null && !"".equals(phone)) {
						Gson gson = new Gson();
						if (phone.contains("[{")) {
							List<Phone> ph = gson.fromJson(phone, new TypeToken<List<Phone>>() {
							}.getType());
							client.setPhlist(ph);
						}
					}

					String quests = client.getQuests();
					if (quests != null && !"".equals(quests)) {
						String ObjContent = "";

						if (client.getDescs() != null && !"".equals(client.getDescs())) {
							boolean flag = StringUtil.getHanzi(client.getDescs());
							if (!flag) {
								try {
									byte[] bytes = StringUtil.hexDecode(quests);
									ObjContent = new String(bytes, "UTF-8");
								} catch (Exception e) {
									e.printStackTrace();
								}
							} else {
								ObjContent = quests;
							}
						}
						if (ObjContent != null && !"".equals(ObjContent)) {
							try {
								JSONArray array = new JSONArray(ObjContent);
								List<Quests> quesList = new ArrayList<Quests>();
								if (array != null && !"".equals(array)) {
									for (int i = 0; i < array.length(); i++) {
										Gson gson = new Gson();
										Quests quest = new Quests();
										quest = gson.fromJson(array.get(i).toString(), Quests.class);
										quesList.add(quest);
									}
									client.setQueList(quesList);
								}
							} catch (JSONException e) {
								e.printStackTrace();
							}
						}
					}
				}

				TgStudent student = new TgStudent();
				student.setPkey(client.getKeyname());
				List<TgStudent> stuList = studentDao.findByExample(student);
				SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");

				if (stuList != null && stuList.size() > 0) {
					for (TgStudent stu : stuList) {
						// 生日转换
						if (stu.getBirthday() != null && !"".equals(stu.getBirthday())) {
							String birthdays = sdf1.format(new Date(stu.getBirthday() * 1000));
							stu.setBirthdays(birthdays);
						}
						// 备注文字解密
						if (stu.getFeature() != null && !"".equals(stu.getFeature())) {
							boolean flag = StringUtil.getHanzi(stu.getFeature());
							if (!flag) {
								try {
									byte[] bytes = StringUtil.hexDecode(stu.getFeature());
									String ObjContent = new String(bytes, "UTF-8");
									stu.setFeature(ObjContent);
								} catch (Exception e) {
									e.printStackTrace();
								}
							}
						}

					}
				}
				TgTracking track = new TgTracking();
				track.setClient(client.getKeyname());
				List<TgTracking> traList = trackingDao.findByExample(track);
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				TgState state = new TgState();
				if (traList != null && traList.size() > 0) {
					for (TgTracking tra : traList) {
						// 状态
						if (tra.getState() != null && !"".equals(tra.getState())) {
							if (tra.getState().contains(",")) {
								String[] stat = tra.getState().split(",");
								if (stat.getClass().isArray()) {
									String stats = "";
									for (int i = 0; i < stat.length; i++) {
										state.setKeyname(stat[i]);
										List<TgState> stateList = stateDao.findByExample(state);
										if (stateList != null && stateList.size() > 0) {
											stats = stats + stateList.get(0).getName() + ",";
										}
									}
									String[] sta = stats.split(",");
									List<State> staList = new ArrayList<State>();
									List<String> person = new ArrayList<>(Arrays.asList(sta));
									for (int j = 0; j < person.size(); j++) {
										State states = new State();
										states.setState(person.get(j));
										staList.add(states);
									}
									tra.setSlist(staList);
								}
							} else {
								state.setKeyname(tra.getState());
								List<TgState> stateList = stateDao.findByExample(state);
								if (stateList != null && stateList.size() > 0) {
									tra.setState(stateList.get(0).getName());
								}
							}
						}
						// 时间转换
						if (tra.getCdate() != null && !"".equals(tra.getCdate())) {
							String createTime = sdf.format(new Date(tra.getCdate() * 1000));
							tra.setCreateTime(createTime);
						}
						// 提醒时间转换
						if (tra.getRemind_date() != null && !"".equals(tra.getRemind_date())) {
							String createTime = sdf1.format(new Date(tra.getRemind_date() * 1000));
							tra.setStartTime(createTime);
						}

						// 备注内容
						if (tra.getRemark() != null && !"".equals(tra.getRemark())) {
							if (StringUtil.isNum(tra.getRemark())) {
								tra.setRemark(tra.getRemark());
							} else {
								boolean flag = StringUtil.getHanzi(tra.getRemark());
								if (!flag) {
									try {
										byte[] bytes = StringUtil.hexDecode(tra.getRemark());
										String ObjContent = new String(bytes, "UTF-8");
										tra.setRemark(ObjContent);
									} catch (Exception e) {
										e.printStackTrace();
									}
								}
							}
						}

						// 负责人
						TgUserinfo user = new TgUserinfo();
						user.setUsername(tra.getUsername());
						List<TgUserinfo> ulist = userinfoDao.findByExample(user);
						if (ulist != null && ulist.size() > 0) {
							tra.setNickname(ulist.get(0).getNickname());
						}
						// 时间转换
						if (tra.getCdate() != null && !"".equals(tra.getCdate())) {
							String createTime = sdf.format(new Date(tra.getCdate() * 1000));
							tra.setCreateTime(createTime);
						}

					}
				}
				// 预约测评数据
				TgUser user = UserUtil.getUserFromCookies();

				TgUserinfo user1 = new TgUserinfo();
				user1.setJob("课程顾问");

				List<TgUserinfo> uList = userinfoDao.getUserInfoByUserInfo(user1);
				List<TgOffice> offList = tgOfficeDao.findAll(TgOffice.class);

				result.setDefaultModel("offList", offList);
				result.setDefaultModel("user", user);
				result.setDefaultModel("traList", traList);
				result.setDefaultModel("client", client);
				result.setDefaultModel("stuList", stuList);
				result.setDefaultModel("uList", uList);
				result.setDefaultModel("reskey", reskey);
				result.setDefaultModel("resdate", resdate);
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	// 获取学生信息
	@RequestMapping(value = "/consultant_student_search")
	public ModelAndView consultanl_student_search(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String keyname = request.getParameter("key");
				TgStudent student = new TgStudent();
				student.setKeyname(keyname);
				List<TgStudent> stuList = studentDao.findByExample(student);
				String key = "";
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

				if (stuList != null && stuList.size() > 0) {
					for (TgStudent stu : stuList) {
						key = stu.getKeyname();
						// 生日转换
						if (stu.getBirthday() != null && !"".equals(stu.getBirthday())) {
							String birthdays = sdf.format(new Date(stu.getBirthday() * 1000));
							stu.setBirthdays(birthdays);
						}
						// 备注文字解密
						if (stu.getFeature() != null && !"".equals(stu.getFeature())) {
							if (StringUtil.isNum(stu.getFeature())) {
								stu.setFeature(stu.getFeature());
							} else {
								boolean flag = StringUtil.getHanzi(stu.getFeature());
								if (!flag) {
									try {
										byte[] bytes = StringUtil.hexDecode(stu.getFeature());
										String ObjContent = new String(bytes, "UTF-8");
										stu.setFeature(ObjContent);
									} catch (Exception e) {
										e.printStackTrace();
									}
								}
							}
						}

					}
				}

				result.setDefaultModel("stuList", stuList);
				result.setDefaultModel("key", stuList.get(0).getKeyname());
				result.setDefaultModel("nickname", stuList.get(0).getNickname());
				result.setDefaultModel("sex", stuList.get(0).getSex());
				result.setDefaultModel("age", stuList.get(0).getAge());
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	// 获取接待人
	@RequestMapping(value = "/consultant_reserve_user_search")
	public ModelAndView consultant_reserve_user_search(ModelMap modelMap, final BaseVo vo,
			final HttpServletRequest request, HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				try {
					String date = request.getParameter("date");
					String time = request.getParameter("time");
					String needtime = request.getParameter("needtime");
					String region = request.getParameter("region");
					String key = request.getParameter("key");
					String city = request.getParameter("city");
					String province = request.getParameter("province");
					TgOffice office = new TgOffice();
					List<TgOffice> nameByCity = new ArrayList<TgOffice>();
					List<TgUserinfo> list = new ArrayList<TgUserinfo>();// 这里的可能有重复的数据
					List<TgUserinfo> listNew = new ArrayList<TgUserinfo>();// 去重后的数据
					List<TgUserinfo> list1 = new ArrayList<TgUserinfo>();
					HashSet<TgUserinfo> set = new HashSet<>();
					if (MathUtil.isNotEmpty(province)) {
						office.setProvince(province);
						nameByCity = tgOfficeDao.getOfficeNameByProvince(province);
						if (MathUtil.isNotEmpty(city) && Constants.isTeDingProvince(province) == 0) {
							office.setCity(city);
							nameByCity = tgOfficeDao.getCoreNameByCity3(office);
						}
						// System.out.println(coreNameByCity2.toString());
						for (TgOffice tgOffice : nameByCity) {
							String exclude = "";
							if (key != null) {
								exclude = "AND keyname!='" + key + "'";
							}
							TgUserinfo userinfo = new TgUserinfo();
							String stamp_l = "";
							Long stamp_r = null;
							SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
							if (date != null && !"".equals(date) && time != null) {
								stamp_l = date + " " + time;
								Long st_l = sdf.parse(stamp_l).getTime() / 1000;
								stamp_r = st_l;
								if (needtime != null && !"".equals(needtime)) {
									stamp_r = st_l + (long) (Double.valueOf(needtime) * 3600);
								}

								userinfo.setRegion(tgOffice.getKeyname());
								userinfo.setStamp_l1(st_l);
								userinfo.setStamp_r1(stamp_r);
								userinfo.setStamp_l2(st_l);
								userinfo.setStamp_r2(stamp_r);
								userinfo.setExclude(exclude);
							}
							list1 = userinfoDao.getReseUser(userinfo);
							list.addAll(list1);
							// 使用hashset去重复，set为重复的集合，可以通过new
							// ArrayList(set)转换成list

							for (TgUserinfo tgUser : list) {
								set.add(tgUser);
							}
							// listNew.clear();
						}

					} else {
						String exclude = "";
						if (key != null) {
							exclude = "AND keyname!='" + key + "'";
						}
						TgUserinfo userinfo = new TgUserinfo();
						String stamp_l = "";
						Long stamp_r = null;
						SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
						if (date != null && !"".equals(date) && time != null) {
							stamp_l = date + " " + time;
							Long st_l = sdf.parse(stamp_l).getTime() / 1000;
							stamp_r = st_l;
							if (needtime != null && !"".equals(needtime)) {
								stamp_r = st_l + (long) (Double.valueOf(needtime) * 3600);
							}

							userinfo.setRegion(region);
							userinfo.setStamp_l1(st_l);
							userinfo.setStamp_r1(stamp_r);
							userinfo.setStamp_l2(st_l);
							userinfo.setStamp_r2(stamp_r);
							userinfo.setExclude(exclude);
						}
						listNew = userinfoDao.getReseUser(userinfo);
					}
					listNew.addAll(set);
					result.setDefaultModel("stuList", listNew);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return result;
			}
		});
		return new ModelAndView("", modelMap);

	}

	// 获取测评老师
	@RequestMapping(value = "/consultant_reserve_uses")
	public ModelAndView consultant_reserve_uses(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String center = request.getParameter("center");
				TgOffice office = new TgOffice();

				String cname = "";
				if (office != null && !"".equals(office)) {
					office.setKeyname(center);
					cname = tgOfficeDao.findByExample(office).get(0).getName();
				}

				try {
					cname = URLEncoder.encode(cname, "utf-8");
				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
				}
				String url = "http://www.yueqiao.org/web/teaweb/getTeacherList.json?center=" + cname;
				String teacher = HttpUtil.doGet(url, "", "utf-8", true);
				net.sf.json.JSONArray obj = new net.sf.json.JSONArray();
				obj = JSONObject.fromObject(teacher).getJSONArray("list");
				List<TgUser> list = new ArrayList<TgUser>();
				for (int i = 0; obj.size() > i; i++) {
					TgUser user = new TgUser();
					JSONObject o = JSONObject.fromObject(obj.get(i));
					user.setNickname(o.getString("name"));
					user.setUsername(o.getString("login_name"));
					user.setRegion(o.getString("center"));
					list.add(user);
				}
				result.setDefaultModel("list", list);
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	// 增加客户接待
	@RequestMapping(value = "/consultant_client_reception_go")
	public ModelAndView consultant_client_reception_go(ModelMap modelMap, final BaseVo vo,
			final HttpServletRequest request, final HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String clientkey = request.getParameter("client");
				String rkey = request.getParameter("rkey");
				String rdate = request.getParameter("rdate");
				String ruser = request.getParameter("ruser");

				String username2 = request.getParameter("target2");
				String pra_type = request.getParameter("pra_type");
				String times = request.getParameter("times");

				String region = request.getParameter("region");
				String worth = request.getParameter("worth");
				String feature = request.getParameter("feature");
				String student = request.getParameter("student");
				String key = request.getParameter("key");
				String money = request.getParameter("money");
				String moneyType = request.getParameter("moneyType");
				String rep_date = request.getParameter("rep_date1");
				String money1 = request.getParameter("money1");
				String moneyType1 = request.getParameter("moneyType1");
				String rep_date2 = request.getParameter("rep_date2");
				String earnestType = request.getParameter("earnestType");
				String nestid = request.getParameter("nestid");
				String nest_date = request.getParameter("nest_date");
				String beizhu = request.getParameter("beizhu");
				String pz_url1 = request.getParameter("all_words");
				String pz_url2 = request.getParameter("all_words2");
				String pz_url3 = request.getParameter("all_words3");
				// String stuKey = request.getParameter("stuKey");//学员key

				// JSONObject obj =
				// JSONObject.fromObject(student).getJSONObject(stuKey);
				// String testTeacher = obj.getString("testuser");

				String keys = "";
				TgReception reception = new TgReception();
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				if (key != null && !"".equals(key)) {
					reception.setKeyname(key);
					List<TgReception> list = receptionDao.findByExample(reception);
					if (list != null && list.size() > 0) {
						reception = list.get(0);
						if (rdate != null && !"".equals(rdate)) {
							Date date = null;
							try {
								date = sdf.parse(rdate);
							} catch (ParseException e) {
								e.printStackTrace();
							}
							reception.setDate(date.getTime() / 1000);
						}

						if (rep_date != null && !"".equals(rep_date)) {
							Date rep_date1 = null;
							try {
								rep_date1 = sdf.parse(rep_date);
							} catch (ParseException e) {
								e.printStackTrace();
							}
							reception.setRep_date(rep_date1.getTime() / 1000);
						}

						if (rep_date2 != null && !"".equals(rep_date2)) {
							Date rep1 = null;
							try {
								rep1 = sdf.parse(rep_date2);
							} catch (ParseException e) {
								e.printStackTrace();
							}
							reception.setRep_date1(rep1.getTime() / 1000);
						}

						if (worth != null && !"".equals(worth)) {
							int wor = Integer.parseInt(worth);
							reception.setWorth(wor);
						}

						if (moneyType != null && !"".equals(moneyType)) {
							reception.setMoneyType(Integer.valueOf(moneyType));
						}

						if (money != null && !"".equals(money)) {
							double mon = Double.parseDouble(money);
							reception.setMoney(mon);
						}

						if (moneyType1 != null && !"".equals(moneyType1)) {
							reception.setMoneyType1(Integer.valueOf(moneyType1));
						}

						if (money1 != null && !"".equals(money1)) {
							double mon = Double.parseDouble(money1);
							reception.setMoney1(mon);
						}

						if (earnestType != null && !"".equals(earnestType)) {
							reception.setEarnestType(Integer.valueOf(earnestType));
						}

						if (nestid != null && !"".equals(nestid)) {
							double earnest = Double.parseDouble(nestid);
							reception.setEarnest(earnest);
						}

						if (nest_date != null && !"".equals(nest_date)) {
							Date nest = null;
							try {
								nest = sdf.parse(nest_date);
							} catch (ParseException e) {
								e.printStackTrace();
							}
							reception.setEarnest_date(nest.getTime() / 1000);
						}

						if (pz_url1 != null && !"".equals(pz_url1)) {
							reception.setPz_url1(pz_url1);
						}
						if (pz_url2 != null && !"".equals(pz_url2)) {
							reception.setPz_url2(pz_url2);
						}
						if (pz_url3 != null && !"".equals(pz_url3)) {
							reception.setPz_url3(pz_url3);
						}

						if (feature != null && !"".equals(feature)) {
							byte[] srtbyte = null;
							try {
								srtbyte = feature.getBytes("UTF-8");
								String bytess = StringUtil.toHex(srtbyte);
								reception.setFeature(bytess);
							} catch (UnsupportedEncodingException e) {
								e.printStackTrace();
							}
						}
						if (student != null && !"".equals(student)) {
							byte[] srtbyte = null;
							try {
								srtbyte = student.getBytes("UTF-8");
								String bytess = StringUtil.toHex(srtbyte);
								reception.setStudent(bytess);
							} catch (UnsupportedEncodingException e) {
								e.printStackTrace();
							}
						}
						if (clientkey != null && !"".equals(clientkey)) {
							reception.setClient(clientkey);
						}
						if (rkey != null && !"".equals(rkey)) {
							reception.setRkey(rkey);
						}
						if (ruser != null && !"".equals(ruser)) {
							reception.setUsername(ruser);
						}

						if (username2 != null && !"".equals(ruser)) {
							reception.setUsername2(username2);
						}
						if (pra_type != null && !"".equals(pra_type)) {
							reception.setPra_type(Integer.valueOf(pra_type));
						}
						if (times != null && !"".equals(times)) {
							reception.setTimes(Integer.valueOf(times));
						}

						if (region != null && !"".equals(region)) {
							reception.setRegion(region);
						}
						if (rkey != null && !"".equals(rkey)) {
							reception.setRkey(rkey);
						}
						reception.setBeizhu(beizhu);
						reception.setNewver(1);
						reception.setMdate(new Date().getTime() / 1000);
						receptionDao.update(reception);
					}
				} else {
					if (rdate != null && !"".equals(rdate)) {
						Date date = null;
						try {
							date = sdf.parse(rdate);
						} catch (ParseException e) {
							e.printStackTrace();
						}
						reception.setDate(date.getTime() / 1000);

					}
					if (worth != null && !"".equals(worth)) {
						int wor = Integer.parseInt(worth);
						reception.setWorth(wor);
					}
					if (rep_date != null && !"".equals(rep_date)) {
						Date rep_date1 = null;
						try {
							rep_date1 = sdf.parse(rep_date);
						} catch (ParseException e) {
							e.printStackTrace();
						}
						reception.setRep_date(rep_date1.getTime() / 1000);
					}

					if (moneyType != null && !"".equals(moneyType)) {
						reception.setMoneyType(Integer.valueOf(moneyType));
					}

					if (money != null && !"".equals(money)) {
						double mon = Double.parseDouble(money);
						reception.setMoney(mon);
					}

					if (pz_url1 != null && !"".equals(pz_url1)) {
						reception.setPz_url1(pz_url1);
					}
					if (pz_url2 != null && !"".equals(pz_url2)) {
						reception.setPz_url2(pz_url2);
					}

					if (earnestType != null && !"".equals(earnestType)) {
						reception.setEarnestType(Integer.valueOf(earnestType));
					}

					if (nestid != null && !"".equals(nestid)) {
						double earnest = Double.parseDouble(nestid);
						reception.setEarnest(earnest);
					}

					if (nest_date != null && !"".equals(nest_date)) {
						Date nest = null;
						try {
							nest = sdf.parse(nest_date);
						} catch (ParseException e) {
							e.printStackTrace();
						}
						reception.setEarnest_date(nest.getTime() / 1000);
					}

					if (username2 != null && !"".equals(ruser)) {
						reception.setUsername2(username2);
					}
					if (pra_type != null && !"".equals(pra_type)) {
						reception.setPra_type(Integer.valueOf(pra_type));
					}
					if (times != null && !"".equals(times)) {
						reception.setTimes(Integer.valueOf(times));
					}

					if (feature != null && !"".equals(feature)) {
						byte[] srtbyte = null;
						try {
							srtbyte = feature.getBytes("UTF-8");
							String bytess = StringUtil.toHex(srtbyte);
							reception.setFeature(bytess);
						} catch (UnsupportedEncodingException e) {
							e.printStackTrace();
						}
					}
					if (student != null && !"".equals(student)) {
						byte[] srtbyte = null;
						try {
							srtbyte = student.getBytes("UTF-8");
							String bytess = StringUtil.toHex(srtbyte);
							reception.setStudent(bytess);
						} catch (UnsupportedEncodingException e) {
							e.printStackTrace();
						}
					}
					keys = SsiUtils.randomUUID();
					reception.setKeyname(keys);
					reception.setClient(clientkey);
					reception.setRkey(rkey);
					reception.setUsername(ruser);
					reception.setRegion(region);
					reception.setNewver(1);
					reception.setBeizhu(beizhu);
					reception.setMdate(new Date().getTime() / 1000);
					receptionDao.insert(reception);
					// 状态改变
					/*
					 * String url =
					 * "http://localhost:8081/web/index/updatereserve.json?keyname="
					 * +rkey+ "&state=2"; try {
					 * response.sendRedirect("/updatereserve.json?keyname="+rkey
					 * +"&state=2");
					 * 
					 * } catch (Exception e) { // TODO: handle exception
					 * e.printStackTrace();
					 * 
					 * } // HttpUtil.doGet(url, "", "utf-8", true);
					 */
					// 5BCCAE99E5C34E2C87CFE3F9A04F1EF0
					result.setDefaultModel("money", money);
					result.setDefaultModel("rep_date", rep_date);
					result.setDefaultModel("nestid", nestid);
					result.setDefaultModel("nest_date", nest_date);
				}
				String keyss = "";
				if (key != null && !"".equals(key)) {
					keyss = key;
				} else {
					keyss = keys;
				}

				result.setDefaultModel("key", keyss);
				result.setDefaultModel("rkey", rkey);
				result.setDefaultModel("student", student);
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	// 修改预约状态
	@RequestMapping(value = "/updatereserve")
	public ModelAndView updatereserve(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String keyname = request.getParameter("keyname");
				String client = request.getParameter("client");
				String username = request.getParameter("username");
				String region = request.getParameter("region");
				String student = request.getParameter("student");
				String non = request.getParameter("non");

				String notice = request.getParameter("notice");
				String date = request.getParameter("date");
				String time = request.getParameter("time");
				String state = request.getParameter("state");
				String states = request.getParameter("states");
				String yuanyin = request.getParameter("yuanyin");
				String sms = request.getParameter("sms");
				String needtime = request.getParameter("needtime");
				String remark = request.getParameter("remark");
				String reception_u = request.getParameter("reception_u");

				TgReserve reserve = new TgReserve();
				TgUser user = UserUtil.getUserFromCookies();

				if (region != null) {
					TgClient client1 = new TgClient();
					client1.setKeyname(client);
					List<TgClient> list = clientDao.findByExample(client1);
					if (list != null && list.size() > 0) {
						client1 = list.get(0);
						if (reception_u != null && !"".equals(reception_u)) {
							client1.setLodusername(reception_u);
							client1.setUsername(reception_u);
							client1.setMdate(new Date().getTime() / 1000);
							clientDao.update(client1);
						}
					}
				}

				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

				if (keyname != null && !"".equals(keyname)) {
					reserve.setKeyname(keyname);
					List<TgReserve> list = reserveDao.findByExample(reserve);
					if (list != null && list.size() > 0) {
						reserve = list.get(0);
						if (reserve != null && !"".equals(reserve)) {
							if (non != null && !"".equals(non)) {
								reserve.setNon(Integer.parseInt(non));
							}
							reserve.setNotice(notice);
							int stat = reserve.getState();

							if (state != null && !"".equals(state)) {
								Integer sta = Integer.parseInt(state);
								reserve.setState(sta);
							}
							try {
								System.out.println(sdf.format(reserve.getDate()));
								// 相同的时间不做修改
								if (!sdf.format(reserve.getDate()).equals(date) || !reserve.getTime().equals(time)) {
									if (reserve.getState() == 1 && !user.getUsername().equals(reserve.getUsername())) {// 待确认的修改(自己修改的不能加上)
										String updateUser = "";
										TgUserinfo userinfo = new TgUserinfo();
										userinfo.setUsername(user.getUsername());
										if (MathUtil.isEmpty(reserve.getUpdate_user())
												|| reserve.getUpdate_user() == "") {
											updateUser = userinfoDao.findByExample(userinfo).get(0).getNickname();
										} else {
											updateUser = reserve.getUpdate_user()
													+ userinfoDao.findByExample(userinfo).get(0).getNickname();
											System.out.println("预约人为：" + updateUser);
										}
										reserve.setUpdate_user(updateUser + ",");

										String updateUserTime = "";
										if (MathUtil.isEmpty(reserve.getUpdate_user_time())
												|| reserve.getUpdate_user_time() == "") {
											updateUserTime = sdf.format(sdf.parse(date)) + " " + time;
										} else {
											updateUserTime = reserve.getUpdate_user_time() + sdf.format(sdf.parse(date))
													+ " " + time;
										}
										reserve.setUpdate_user_time(updateUserTime + ",");
									}
								}
							} catch (ParseException e) {
							}
							try {
								if (date != null && !"".equals(date)) {
									reserve.setDate(sdf.parse(date));
									if (stat == 3) {
										reserve.setState(1);
									}
								}
							} catch (Exception e) {
								e.printStackTrace();
							}
							reserve.setTime(time);
							if (sms != null && !"".equals(sms)) {
								reserve.setSms(Integer.parseInt(sms));
							}
							if (student != null && !"".equals(student)) {
								reserve.setStudent(student);
							}
							if (region != null && !"".equals(region)) {
								reserve.setRegion(region);

							}
							if (client != null && !"".equals(client)) {
								reserve.setClient(client);
							}
							if (reception_u != null && !"".equals(reception_u)) {
								reserve.setReception_u(reception_u);
							}
							if (needtime != null && !"".equals(needtime)) {

								reserve.setNeedtime(needtime);
							}

							if (remark != null && "".equals(remark)) {
								if (StringUtil.getHanzi(remark)) {
									reserve.setRemark(remark);
								}
							}
							reserve.setRemark("备注:" + remark);
							reserve.setMdate(new Date().getTime() / 1000);
							reserveDao.update(reserve);
						}
					}
				} else {
					if (non != null && !"".equals(non)) {
						reserve.setNon(Integer.parseInt(non));
					}
					reserve.setNotice(notice);
					try {
						if (date != null && !"".equals(date)) {
							reserve.setDate(sdf.parse(date));
						}
					} catch (Exception e) {
						e.printStackTrace();
					}
					reserve.setTime(time);
					if (state != null && !"".equals(state)) {
						reserve.setState(Integer.parseInt(state));
					} else {
						reserve.setState(1);
					}
					if (sms != null && !"".equals(sms)) {
						reserve.setSms(Integer.parseInt(sms));
					}
					String keys = SsiUtils.randomUUID();
					reserve.setKeyname(keys);
					reserve.setUsername(username);
					reserve.setUsername_2(username);
					reserve.setStudent(student);
					reserve.setRegion(region);
					reserve.setClient(client);
					reserve.setState2(states);
					reserve.setYuanyin(yuanyin);
					reserve.setReception_u(reception_u);
					reserve.setNeedtime(needtime);
					if (StringUtil.getHanzi(remark)) {
						reserve.setRemark(remark);
					}
					reserve.setRemark("备注:" + remark);
					reserve.setCdate(new Date().getTime() / 1000);
					reserve.setMdate(new Date().getTime() / 1000);
					reserveDao.insert(reserve);
				}
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	// 保存非测评的原因
	@RequestMapping(value = "/updatereserve2")
	public ModelAndView updatereserve2(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String[] states = request.getParameterValues("states");
				String keyname = request.getParameter("keyname");
				String yuanyin = request.getParameter("yuanyin");
				TgReserve reserve = new TgReserve();
				StringBuffer sb = new StringBuffer();
				for (int i = 0; i < states.length; i++) {
					sb.append(states[i]);
				}
				String s = sb.toString();
				if (keyname != null && !"".equals(keyname)) {
					reserve.setKeyname(keyname);
					List<TgReserve> list = reserveDao.findByExample(reserve);
					if (list != null && list.size() > 0) {
						reserve = list.get(0);
						if (reserve != null && !"".equals(reserve)) {
							if (s != null && !"".equals(s)) {
								reserve.setState2(s);
							}
							if (reserve != null && !"".equals(reserve)) {
								if (yuanyin != null && !"".equals(yuanyin)) {
									reserve.setYuanyin(yuanyin);
								}
							}
							reserveDao.update(reserve);
						}
					}
				}
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	@RequestMapping("text1")
	private String checkbxYuyue(HttpServletRequest request, HttpServletResponse response,
			@RequestParam(value = "text1") String text1) {

		System.out.println(text1);
		return text1;
	}

	// 定时提醒查询1
	@RequestMapping(value = "/remind_date")
	public ModelAndView remind_date(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				TgUser user = UserUtil.getUserFromCookies();

				if (user.getUsername().equals("system")) {
					result.setDefaultModel("list", 0);
					return result;
				} else {
					TgTracking tracking = new TgTracking();
					tracking.setUsername(user.getUsername());
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
					String time = sdf.format(new Date());
					try {
						tracking.setRemind_date(sdf.parse(time).getTime() / 1000);
					} catch (ParseException e) {
						e.printStackTrace();
					}
					List<TgTracking> list = trackingDao.findByExample(tracking);
					TgClient client = new TgClient();

					if (list != null && list.size() > 0) {
						List<TgClient> clist = new ArrayList<TgClient>();
						for (TgTracking tra : list) {
							client.setKeyname(tra.getClient());
							List<TgClient> cllist = clientDao.findByExample(client);
							clist.add(cllist.get(0));
						}
						result.setDefaultModel("clist", clist);
					}

					result.setDefaultModel("list", list);
				}
				return result;
			}

		});
		return new ModelAndView("", modelMap);
	}

	// 当日跟踪客户统计
	@RequestMapping(value = "/consultant_personal_today")
	public ModelAndView consultant_personal_today(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = WebExecutor.execute(logger, vo, new Biz() {
			public Result process() {
				String date = request.getParameter("datetime");
				Result result = new ResultSupport(true);
				TgUser user = UserUtil.getUserFromCookies();
				TgClient client = new TgClient();
				client.setUsername(user.getUsername());
				client.setInvalid(0);

				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				String today = "";
				String BeforetwoDay = "";
				String BeforeDay = "";
				String tommorrow1 = "";
				String tommorrow2 = "";
				String tommorrow3 = "";
				String tommorrow4 = "";
				String newday = "";
				String first = "";
				String end = "";
				Date currentDate = null;
				if (date != null && !"".equals(date)) {
					try {
						currentDate = sdf.parse(date);
					} catch (ParseException e) {
						e.printStackTrace();
					} // 今天
					newday = date;
					Calendar rightNow = Calendar.getInstance();
					rightNow.setTime(currentDate);
					rightNow.add(Calendar.DAY_OF_YEAR, -1);
					String ate = sdf.format(rightNow.getTime());
					try {
						currentDate = sdf.parse(ate);
					} catch (ParseException e) {
						e.printStackTrace();
					}
				} else {
					newday = sdf.format(DateUtil.getToDay());
					currentDate = new Date();
					Calendar rightNow = Calendar.getInstance();
					rightNow.setTime(currentDate);
					rightNow.add(Calendar.DAY_OF_YEAR, -1);
					String ate = sdf.format(rightNow.getTime());
					try {
						currentDate = sdf.parse(ate);
					} catch (ParseException e) {
						e.printStackTrace();
					}
				}
				List<Date> days = DateUtil.dateToWeek(currentDate);
				first = sdf.format(DateUtil.DateAdd(days.get(0), -1));
				end = sdf.format(DateUtil.DateAdd(days.get(6), 1));
				days.add(7, DateUtil.DateAdd(days.get(6), 1));

				BeforetwoDay = sdf.format(days.get(0)).substring(0, 10);
				BeforeDay = sdf.format(days.get(1)).substring(0, 10);
				today = sdf.format(days.get(2)).substring(0, 10);
				tommorrow1 = sdf.format(days.get(3)).substring(0, 10);
				tommorrow2 = sdf.format(days.get(4)).substring(0, 10);
				tommorrow3 = sdf.format(days.get(5)).substring(0, 10);
				tommorrow4 = sdf.format(days.get(6)).substring(0, 10);

				TgTracking tracking = new TgTracking();
				List<Integer> list1 = new ArrayList<Integer>();
				for (int j = 1; j < days.size(); j++) {
					tracking.setUsername(client.getUsername());
					tracking.setStaTime(days.get(j - 1).getTime() / 1000);
					tracking.setEnTime(days.get(j).getTime() / 1000);
					Integer cont = trackingDao.getTrackCountByType(tracking);
					list1.add(cont);
				}
				TgOffice office = new TgOffice();
				List<TgOffice> offList = tgOfficeDao.getOfficeName(office);
				result.setDefaultModel("offList", offList);
				result.setDefaultModel("list1", list1);
				result.setDefaultModel("BeforetwoDay", BeforetwoDay);
				result.setDefaultModel("BeforeDay", BeforeDay);
				result.setDefaultModel("today", today);
				result.setDefaultModel("tommorrow1", tommorrow1);
				result.setDefaultModel("tommorrow2", tommorrow2);
				result.setDefaultModel("tommorrow3", tommorrow3);
				result.setDefaultModel("tommorrow4", tommorrow4);
				result.setDefaultModel("newday", newday);
				return result;
			}
		});
		return new ModelAndView("consultant/consultant_tracking_temp", modelMap);
	}

	// 当周跟踪客户统计-分配
	@RequestMapping(value = "/consultant_personal_today_allot")
	public ModelAndView consultant_personal_today_allot(ModelMap modelMap, final BaseVo vo,
			final HttpServletRequest request, HttpServletResponse response) throws BaseException {
		modelMap = WebExecutor.execute(logger, vo, new Biz() {
			public Result process() {
				String date = request.getParameter("datetime");
				String tea_name = request.getParameter("tea_name");
				String center = request.getParameter("center");
				Result result = new ResultSupport(true);
				TgUser user = UserUtil.getUserFromCookies();
				TgClient client = new TgClient();
				client.setUsername(tea_name);
				client.setInvalid(0);

				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				String today = "";
				String BeforetwoDay = "";
				String BeforeDay = "";
				String tommorrow1 = "";
				String tommorrow2 = "";
				String tommorrow3 = "";
				String tommorrow4 = "";
				String newday = "";
				String first = "";
				String end = "";
				Date currentDate = null;
				if (date != null && !"".equals(date)) {
					try {
						currentDate = sdf.parse(date);
					} catch (ParseException e) {
						e.printStackTrace();
					} // 今天
					newday = date;
					Calendar rightNow = Calendar.getInstance();
					rightNow.setTime(currentDate);
					rightNow.add(Calendar.DAY_OF_YEAR, -1);
					String ate = sdf.format(rightNow.getTime());
					try {
						currentDate = sdf.parse(ate);
					} catch (ParseException e) {
						e.printStackTrace();
					}
				} else {
					newday = sdf.format(DateUtil.getToDay());
					currentDate = new Date();
					Calendar rightNow = Calendar.getInstance();
					rightNow.setTime(currentDate);
					rightNow.add(Calendar.DAY_OF_YEAR, -1);
					String ate = sdf.format(rightNow.getTime());
					try {
						currentDate = sdf.parse(ate);
					} catch (ParseException e) {
						e.printStackTrace();
					}
				}
				List<Date> days = DateUtil.dateToWeek(currentDate);
				first = sdf.format(DateUtil.DateAdd(days.get(0), -1));
				end = sdf.format(DateUtil.DateAdd(days.get(6), 1));
				days.add(7, DateUtil.DateAdd(days.get(6), 1));

				BeforetwoDay = sdf.format(days.get(0)).substring(0, 10);
				BeforeDay = sdf.format(days.get(1)).substring(0, 10);
				today = sdf.format(days.get(2)).substring(0, 10);
				tommorrow1 = sdf.format(days.get(3)).substring(0, 10);
				tommorrow2 = sdf.format(days.get(4)).substring(0, 10);
				tommorrow3 = sdf.format(days.get(5)).substring(0, 10);
				tommorrow4 = sdf.format(days.get(6)).substring(0, 10);

				TgTracking tracking = new TgTracking();
				List<Integer> list1 = new ArrayList<Integer>();
				for (int j = 1; j < days.size(); j++) {
					tracking.setUsername(client.getUsername());
					tracking.setStaTime(days.get(j - 1).getTime() / 1000);
					tracking.setEnTime(days.get(j).getTime() / 1000);
					Integer cont = trackingDao.getTrackCountByType(tracking);
					list1.add(cont);
				}
				if (null != center && !center.equals("")) {
					TgUserinfo userinfo = new TgUserinfo();
					userinfo.setRegion(center);
					// 根据中心名查询所以在职的咨询师
					List<TgUserinfo> userlist = userinfoDao.findByExample2(userinfo);
					if (userlist != null && userlist.size() > 0) {
						result.setDefaultModel("userlist", userlist);
					}
				}
				TgOffice office = new TgOffice();
				List<TgOffice> offList = tgOfficeDao.getOfficeName(office);
				result.setDefaultModel("offList", offList);
				result.setDefaultModel("list1", list1);
				result.setDefaultModel("BeforetwoDay", BeforetwoDay);
				result.setDefaultModel("BeforeDay", BeforeDay);
				result.setDefaultModel("today", today);
				result.setDefaultModel("tommorrow1", tommorrow1);
				result.setDefaultModel("tommorrow2", tommorrow2);
				result.setDefaultModel("tommorrow3", tommorrow3);
				result.setDefaultModel("tommorrow4", tommorrow4);
				result.setDefaultModel("newday", newday);
				result.setDefaultModel("center", center);
				result.setDefaultModel("tea_name", tea_name);
				return result;
			}
		});
		return new ModelAndView("consultant/consultant_tracking_temp_allot", modelMap);
	}

	// 根据中心获取咨询老师
	@RequestMapping(value = "/getTeacherBycenter")
	public ModelAndView getTeacherBycenter(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String keyname = request.getParameter("keyname");

				if (null != keyname && !keyname.equals("")) {
					TgUserinfo userinfo = new TgUserinfo();
					userinfo.setRegion(keyname);
					// 根据中心名查询所以在职的咨询师
					List<TgUserinfo> userlist = userinfoDao.findByExample2(userinfo);
					if (userlist != null && userlist.size() > 0) {
						result.setDefaultModel("userlist", userlist);
					}
				}
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	// 添加渠道来源
	@RequestMapping(value = "/consultant_source_add_go")
	public ModelAndView consultant_source_add_go(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String name = request.getParameter("name");
				String explain = request.getParameter("explain");

				TgSource source = new TgSource();
				String key = SsiUtils.randomUUID().substring(0, 12);
				source.setKeyname(key);
				if (name != null && !"".equals(name)) {
					source.setName(name);
				}
				source.setExplains(explain);
				sourceDao.saveOrUpdate(source);
				result.setDefaultModel("key", key);
				result.setDefaultModel("name", name);
				result.setDefaultModel("explain", explain);
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	// 获取方案
	@RequestMapping(value = "/plan_apply")
	public ModelAndView plan_apply(ModelMap modelMap, final LoginVo loginVo, final HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, loginVo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String stu_name = request.getParameter("stu_name");
				String ischeck = request.getParameter("check");
				String currPage = request.getParameter("currPage");
				if (currPage == null || " ".equals(currPage)) {
					currPage = "1";

				}

				TgUser user = UserUtil.getUserFromCookies();
				int tea_id = Integer.parseInt(user.getId().toString());
				String type = "2";
				String name = "";
				String check = "";
				try {
					if (stu_name != null && !" ".equals(stu_name)) {
						name = URLEncoder.encode(stu_name, "utf-8");
					}
					if (ischeck != null && !" ".equals(ischeck)) {
						check = URLEncoder.encode(ischeck, "utf-8");
					}
				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
				}
				String url = "http://www.yueqiao.org/web/teaweb/practice.json?tea_id=" + tea_id + "&type=" + type
						+ "&check=" + check + "&name=" + name + "&currPage=" + currPage;
				String teacher = HttpUtil.doGet(url, "", "utf-8", true);
				// 分页
				JSONObject pageObj = new JSONObject();
				pageObj = JSONObject.fromObject(teacher).getJSONObject("page");

				net.sf.json.JSONArray obj = new net.sf.json.JSONArray();
				obj = JSONObject.fromObject(teacher).getJSONArray("list");
				net.sf.json.JSONArray typeList = JSONObject.fromObject(teacher).getJSONArray("typeList");
				List<Practice> list = new ArrayList<Practice>();
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				for (int i = 0; obj.size() > i; i++) {
					Practice prac = new Practice();
					JSONObject o = JSONObject.fromObject(obj.get(i));
					prac.setStu_id(o.getLong("stu_id"));
					prac.setId(o.getLong("id"));
					prac.setStu_name(o.getString("stu_name"));
					prac.setCourse_type(o.getString("course_type"));
					prac.setStudent_msg(o.getString("student_msg"));
					prac.setPoint(o.getString("point").equals("null") ? "" : o.getString("point"));
					prac.setBeizhu(o.getString("beizhu"));
					prac.setJuti_times(o.getString("juti_times").equals("null") ? "" : o.getString("juti_times"));
					prac.setIscheck(o.getString("ischeck"));
					prac.setUrl(o.getString("url"));
					prac.setOname(o.getString("oname"));
					prac.setIs_xiazai(o.getInt("is_xiazai"));
					try {
						prac.setUseful_time(sdf.parse(sdf.format(o.getLong("useful_time"))));
					} catch (ParseException e) {
						e.printStackTrace();
					}
					list.add(prac);
				}

				Page page = new Page();
				if (typeList != null && !"".equals(typeList)) {
					Gson gson = new Gson();
					String s = pageObj.toString();
					page = gson.fromJson(s, Page.class);
				}
				result.setDefaultModel("page", page);
				result.setDefaultModel("typeList", typeList);
				result.setDefaultModel("list", list);
				result.setDefaultModel("ischeck", ischeck);
				result.setDefaultModel("stu_name", stu_name);
				return result;
			}
		});
		return new ModelAndView("consultant/consultant_apply", modelMap);
	}

	// add添加方案
	@RequestMapping(value = "/consultant_apply_add")
	public ModelAndView consultant_apply_add(ModelMap modelMap, final LoginVo loginVo, final HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, loginVo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String id = request.getParameter("id");
				String region = request.getParameter("region");
				String bool = request.getParameter("bool");
				String practiceid = request.getParameter("practiceid");

				if (practiceid != null && !"".equals(practiceid)) {
					int tea_id = Integer.parseInt(practiceid);
					String urls = "http://www.yueqiao.org/web/teaweb/getPricateById.json?id=" + tea_id;
					String teachers = HttpUtil.doGet(urls, "", "utf-8", true);
					JSONObject practice1 = JSONObject.fromObject(teachers).getJSONObject("practice");

					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
					SimpleDateFormat sdf2 = new SimpleDateFormat("HH:mm:ss");
					Practice prac = new Practice();
					prac.setStu_id(practice1.getLong("stu_id"));
					prac.setId(practice1.getLong("id"));
					prac.setTea_id(practice1.getLong("tea_id"));
					prac.setStu_name(practice1.getString("stu_name"));
					prac.setCenter(practice1.getString("center"));
					prac.setCs_center(practice1.getString("cs_center"));
					prac.setCourse_type(practice1.getString("course_type"));
					prac.setStudent_msg(practice1.getString("student_msg"));
					prac.setPoint(practice1.getString("point"));
					prac.setBeizhu(practice1.getString("beizhu"));
					prac.setJuti_times(practice1.getString("juti_times"));
					prac.setIscheck(practice1.getString("ischeck"));
					prac.setPhone(practice1.getString("phone"));
					prac.setUrl(practice1.getString("url"));
					prac.setFirst(practice1.getString("first"));
					prac.setLoginName(practice1.getString("login_name"));
					prac.setOname(practice1.getString("oname"));
					prac.setJd_center(practice1.getString("jd_center"));
					prac.setTo_name(practice1.getString("to_name"));

					try {
						prac.setUseful_time(sdf.parse(sdf.format(practice1.getLong("useful_time"))));
					} catch (ParseException e) {
						e.printStackTrace();
					}
					String date = "";
					String sfm = "";
					try {
						date = sdf1.format(practice1.getLong("useful_time"));

						sfm = sdf2.format(sdf.parse(sdf.format(practice1.getLong("useful_time"))));
					} catch (ParseException e) {
						e.printStackTrace();
					}
					String shi = sfm.replace(":", "").substring(0, 2);
					String fen = sfm.replace(":", "").substring(2, 4);
					String miao = sfm.replace(":", "").substring(4, 6);
					result.setDefaultModel("date2", date);
					result.setDefaultModel("shi", shi);
					result.setDefaultModel("fen", fen);
					result.setDefaultModel("miao", miao);

					result.setDefaultModel("practice", prac);

				} else {
					TgUser user = UserUtil.getUserFromCookies();
					TgStudent stu = new TgStudent();
					if (id != null && !" ".equals(id)) {
						stu.setId((long) Integer.parseInt(id));
						List<TgStudent> stulist = studentDao.getApply(stu);
						if (stulist != null && stulist.size() > 0) {
							stu = stulist.get(0);
							if (stu.getPhone() != null && !"".equals(stu.getPhone())) {
								Gson gson = new Gson();// new一个Gson对象
								if (stu.getPhone().contains("[{")) {
									List<Phone> phone = gson.fromJson(stu.getPhone(), new TypeToken<List<Phone>>() {
									}.getType());
									stu.setPhone(phone.get(0).getPhone());
								}
							}
							// 学员情况
							if (stu.getFeature() != null && !"".equals(stu.getFeature())) {
								stu.setFeature(stu.getFeature().replace("&nbsp;", "").trim().replace('\"', ' ')
										.replaceAll("</?[^<]+>", ""));
								boolean flag = StringUtil.getHanzi(stu.getFeature());
								if (!flag) {
									try {
										byte[] bytes = StringUtil.hexDecode(stu.getFeature());
										String ObjContent = new String(bytes, "UTF-8");
										if (ObjContent != null && !"".equals(ObjContent)) {
											if (ObjContent.contains("\"")) {
												ObjContent = ObjContent.replace('"', ' ').replaceAll("</?[^<]+>", "")
														.trim();
											}
										}
										stu.setFeature(ObjContent);
									} catch (Exception e) {
										e.printStackTrace();
									}
								} else {
									if (stu.getFeature().contains("\"")) {
										stu.setFeature(
												stu.getFeature().replace('"', ' ').replaceAll("</?[^<]+>", "").trim());
									}
								}
							}
						}
						result.setDefaultModel("list", stu);
						result.setDefaultModel("user", user);
						result.setDefaultModel("bool", bool);
						result.setDefaultModel("region", region);
					}
				}

				// 获取训练类型和点位
				String url = "http://www.yueqiao.org/web/teaweb/getkcAndDw.json";
				String teacher = HttpUtil.doGet(url, "", "utf-8", true);
				net.sf.json.JSONArray typeList = JSONObject.fromObject(teacher).getJSONArray("typeList");
				net.sf.json.JSONArray coursetype = JSONObject.fromObject(teacher).getJSONArray("coursetype");

				List<TgOffice> office_List = tgOfficeDao.findAll(TgOffice.class);
				result.setDefaultModel("office_List", office_List);
				result.setDefaultModel("typeList", typeList);
				result.setDefaultModel("coursetype", coursetype);

				return result;
			}
		});
		return new ModelAndView("consultant/consultant_apply_add", modelMap);
	}

	// 添加训练方案
	@RequestMapping(value = "/add_apply")
	public ModelAndView add_apply(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String id = request.getParameter("id");
				String stu_id = request.getParameter("stu_id");
				String stu_name = request.getParameter("stu_name");
				String tea_id = request.getParameter("tea_id");
				String to_name = request.getParameter("to_name");
				String course_type = request.getParameter("course_type");
				String cs_center = request.getParameter("cs_center");
				String stat = request.getParameter("stat");
				String phone = request.getParameter("phone");
				String member = request.getParameter("member");
				String type = "2";
				String student_msg = request.getParameter("student_msg");
				String stime = request.getParameter("stime");
				String center = request.getParameter("center");
				String beizhu = request.getParameter("beizhu");
				String jd_center = request.getParameter("jd_center");

				try {
					id = URLEncoder.encode(id, "utf-8");
					type = URLEncoder.encode(type, "utf-8");
					stu_id = URLEncoder.encode(stu_id, "utf-8");
					cs_center = URLEncoder.encode(cs_center, "utf-8");
					phone = URLEncoder.encode(phone, "utf-8");
					member = URLEncoder.encode(member, "utf-8");
					stu_name = URLEncoder.encode(stu_name, "utf-8");
					stat = URLEncoder.encode(stat, "utf-8");
					tea_id = URLEncoder.encode(tea_id, "utf-8");

					to_name = URLEncoder.encode(to_name, "utf-8");
					course_type = URLEncoder.encode(course_type, "utf-8");
					student_msg = URLEncoder.encode(student_msg.trim(), "utf-8");
					stime = URLEncoder.encode(stime, "utf-8");
					center = URLEncoder.encode(center, "utf-8");
					beizhu = URLEncoder.encode(beizhu, "utf-8");
					jd_center = URLEncoder.encode(jd_center, "utf-8");

				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
				}
				result.setDefaultModel("msg", "0");
				String url = "http://www.yueqiao.org/web/teaweb/saveapply.json?id=" + id + "&stu_id=" + stu_id
						+ "&stu_name=" + stu_name + "&tea_id=" + tea_id + "&to_name=" + to_name + "&course_type="
						+ course_type + "&student_msg=" + student_msg + "&stime=" + stat + "&center=" + center
						+ "&type=" + type + "&cs_center=" + cs_center + "&beizhu=" + beizhu + "&phone=" + phone
						+ "&loginName=" + member + "&first=" + stime + "&jd_center=" + jd_center;
				String res = HttpUtil.doGet(url, "", "utf-8", true);
				result.setDefaultModel("msg", "1");
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	// 删除方案
	@RequestMapping(value = "/delete_apply")
	public ModelAndView delete_apply(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String ids = request.getParameter("clients");
				String url = "http://www.yueqiao.org/web/teaweb/deletePracticeById.json?ids=" + ids;
				String teacher = HttpUtil.doGet(url, "", "utf-8", true);
				String msg = JSONObject.fromObject(teacher).getString("msg");
				result.setDefaultModel("msg", msg);
				System.out.println(msg);
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	// 修改方案已下载
	@RequestMapping(value = "/updateIsxiazai")
	public ModelAndView updateIsxiazai(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String id = request.getParameter("id");
				String url = "http://www.yueqiao.org/web/teaweb/updateIsxiazai.json?id=" + id;
				String teacher = HttpUtil.doGet(url, "", "utf-8", true);
				result.setDefaultModel("msg", "1");
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	// 绩效统计
	@RequestMapping(value = "/consultant_performance_stat")
	public ModelAndView consultant_performance_stat(ModelMap modelMap, final LoginVo loginVo,
			final HttpServletRequest request, final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, loginVo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String startTime = request.getParameter("sdate");
				String keuser = request.getParameter("keuser");
				String type = request.getParameter("type");

				String region = "";
				Long qqgroup = null;
				if (keuser == null || "".equals(keuser)) {
					keuser = "liuyun";
					region = "c9qbtw1fzvc6";
				} else {
					TgUserinfo user2 = new TgUserinfo();
					user2.setUsername(keuser);
					List<TgUserinfo> uList1 = userinfoDao.getUserInfoByUserInfo(user2);
					if (uList1 != null && uList1.size() > 0) {
						region = uList1.get(0).getRegion();
						qqgroup = uList1.get(0).getQq_group();
					}
				}
				TgUserinfo user1 = new TgUserinfo();
				user1.setJob("课程顾问");
				List<TgUserinfo> uList1 = null;
				List<TgUserinfo> uList3 = null;
				uList1 = userinfoDao.getUserInfoByUserInfo(user1);
				// 查询行政部老师
				uList3 = userinfoDao.getUserInfoByUserInfo3(user1);
				uList1.addAll(uList3);

				TgUser user = UserUtil.getUserFromCookies();
				SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
				String sdate = "";
				try {
					Date start = null;
					Date end = null;
					List<Date> dlist = DateUtil.getMdatefandl(startTime);
					if (dlist != null && dlist.size() > 0) {
						start = dlist.get(0);
						end = dlist.get(1);
						sdate = df.format(start);
					}
					result.setDefaultModel("sdate", sdate);
					result.setDefaultModel("start", start);
					result.setDefaultModel("end", end);

					// 查询月任务量
					TgWorkload workload = new TgWorkload();
					if (startTime != null && !"".equals(startTime)) {
						workload.setMonth(df.parse(startTime).getTime() / 1000);
					} else {
						workload.setMonth(df.parse(df.format(new Date())).getTime() / 1000);
					}
					if (user.getUsergroup() == 3) {
						if (user.getMenu() != null && user.getMenu().contains("d")) {
							if (type.equals("2")) {
								workload.setTotal_region(user.getRegion());
							} else if (type.equals("1")) {
								workload.setTotal_region(region);
							}
						} else {
							workload.setTotal_region(user.getRegion());
						}
					} else {
						workload.setTotal_region(region);
					}
					Integer money = workloadDao.getWorkloadMoney(workload);
					Integer rece = workloadDao.getWorkloadRece(workload);
					Integer res = workloadDao.getWorkloadReserve(workload);
					Integer tr = workloadDao.getWorkloadTrack(workload);
					// 本月接待数据统计
					TgUsernames userns = new TgUsernames();
					TgReception reception = new TgReception();
					reception.setStartTime(start.getTime() / 1000);
					reception.setEndTime(end.getTime() / 1000);
					if (user.getUsergroup() == 3) {
						if (user.getMenu() != null && user.getMenu().contains("d")) {
							if (type.equals("2")) {
								reception.setUsername(user.getUsername());
								userns.setUsername(user.getUsername());
							} else if (type.equals("1")) {
								reception.setUsername(keuser);
								userns.setUsername(keuser);
							}
						} else {
							reception.setUsername(user.getUsername());
							userns.setUsername(user.getUsername());
						}
					} else {
						reception.setUsername(keuser);
						userns.setUsername(keuser);
					}

					// 总接待
					Integer zonRece = receptionService.getZonlReceptionCount(reception);

					Integer zonChendan = receptionDao.getDanReceptionCount(reception);
					result.setDefaultModel("zonRece", zonRece);
					result.setDefaultModel("zonChendan", zonChendan);
					float sum = (float) 0;

					TgMoney mon = new TgMoney();
					TgMoney mon2 = new TgMoney();
					if (user.getUsergroup() == 3) {
						if (user.getMenu() != null && user.getMenu().contains("d")) {
							if (type.equals("2")) {
								mon.setUsername(user.getUsername());
								mon2.setUsername(user.getUsername());
							} else if (type.equals("1")) {
								mon.setUsername(keuser);
								mon2.setUsername(keuser);
							}
						} else {
							mon.setUsername(user.getUsername());
							mon2.setUsername(user.getUsername());
						}
					} else {
						mon.setUsername(keuser);
						mon2.setUsername(keuser);
					}

					// 新增总金额
					sum = moneyService.getZonXzMoneys(mon, mon2, start, end);

					// 本月预约数据统计
					TgReserve reserve = new TgReserve();
					TgUser users = new TgUser();
					reserve.setStart(start.getTime() / 1000);
					reserve.setEnd(end.getTime() / 1000);
					if (user.getUsergroup() == 3) {
						if (user.getMenu() != null && user.getMenu().contains("d")) {
							if (type.equals("2")) {
								reserve.setUsername(user.getUsername());
								users.setUsername(user.getUsername());
							} else if (type.equals("1")) {
								reserve.setUsername(keuser);
								users.setUsername(keuser);
							}
						} else {
							reserve.setUsername(user.getUsername());
							users.setUsername(user.getUsername());
						}
					} else {
						reserve.setUsername(keuser);
						users.setUsername(keuser);
					}
					Integer shidao = reserveDao.getShidaoReserveCountBy(reserve);// 实到数量

					// 每月有效电话完成情况
					TgTracking tracking = new TgTracking();
					if (user.getUsergroup() == 3) {
						if (user.getMenu() != null && user.getMenu().contains("d")) {
							if (type.equals("2")) {
								tracking.setUsername(user.getUsername());
							} else if (type.equals("1")) {
								tracking.setUsername(keuser);
							}
						} else {
							tracking.setUsername(user.getUsername());
						}
					} else {
						tracking.setUsername(keuser);
					}
					tracking.setStaTime(start.getTime() / 1000);
					tracking.setEnTime(end.getTime() / 1000);
					Integer cont = trackingDao.getTrackCountByType(tracking);

					float scale_money = 0;
					double scale_reception = 0;
					float scale_reserve = 0;
					float scale_track = 0;
					DecimalFormat fnum = new DecimalFormat("#.#");
					DecimalFormat fnum1 = new DecimalFormat("#.##%");

					// 个人月度业绩完成率
					if (sum != 0 && money != null && money != 0) {
						float divider = money * 10000;
						float scale = (float) sum / divider;
						scale_money = scale;
						String sum_money = fnum1.format(scale_money);

						result.setDefaultModel("divider", divider);
						result.setDefaultModel("sum", sum);
						result.setDefaultModel("sum_money", sum_money);
					} else {
						result.setDefaultModel("sum_money", 0);
					}
					// 当月接待成功率
					float scale1 = 0;
					if (zonChendan != 0) {
						scale1 = (float) zonChendan / zonRece;
					}
					if (scale1 != 0 && rece != null && rece != 0) {
						double sc = (double) scale1 / (rece) * 100;
						if (sc != 0 && sc > 1.5) {
							sc = (float) 1.5;
						}
						scale_reception = sc * 40;
						String sum_rece = fnum.format(scale_reception);
						result.setDefaultModel("rece", rece);
						result.setDefaultModel("scale1", scale1 * 100);
						result.setDefaultModel("sum_rece", sum_rece);
					} else {
						result.setDefaultModel("sum_rece", 0);
					}
					// 当月实际到访率
					if (shidao != 0 && res != null && res != 0) {
						float rese = (float) shidao / res;
						if (rese != 0 && rese > 1.5) {
							rese = (float) 1.5;
						}
						scale_reserve = rese * 40;
						String sum_reserve = fnum.format(scale_reserve);
						result.setDefaultModel("res", res);
						result.setDefaultModel("shidao", shidao);
						result.setDefaultModel("sum_reserve", sum_reserve);

					} else {
						result.setDefaultModel("sum_reserve", 0);
					}
					// 每月有效电话完成情况
					if (cont != 0 && tr != null && tr != 0) {
						float track = (float) cont / tr;
						scale_track = track;
						String sum_track = fnum1.format(scale_track);
						result.setDefaultModel("tr", tr);
						result.setDefaultModel("cont", cont);
						result.setDefaultModel("sum_track", sum_track);
					} else {
						result.setDefaultModel("sum_track", 0);
					}
					// 中心打分和基准值
					TgUsergrade usergrade = new TgUsergrade();
					PerformanceInfo info = new PerformanceInfo();
					if (user.getUsergroup() == 3) {
						if (user.getMenu() != null && user.getMenu().contains("d")) {
							if (type.equals("2")) {
								usergrade.setUsername(user.getUsername());
								info.setUsername(user.getUsername());
							} else if (type.equals("1")) {
								usergrade.setUsername(keuser);
								info.setUsername(keuser);
							}
						} else {
							usergrade.setUsername(user.getUsername());
							info.setUsername(user.getUsername());
						}
					} else {
						usergrade.setUsername(keuser);
						info.setUsername(keuser);
					}

					if (startTime == null || "".equals(startTime)) {
						usergrade.setDate(df.format(new Date()));
					} else {
						usergrade.setDate(startTime);
					}
					List<TgUsergrade> gradeList = null;
					Integer dfcount = 0;
					if (qqgroup != null && !"null".equals(qqgroup) && qqgroup == 8) {
						// 根据行政人员的名字和日期查询月平均分
						gradeList = usergradeDao.getTgUsergrade2(usergrade);
						dfcount = gradeList.get(0).getAvg();
					} else {
						gradeList = usergradeDao.getTgUsergrade(usergrade);
						if (gradeList != null && gradeList.size() > 0) {
							for (TgUsergrade g : gradeList) {
								dfcount = dfcount + g.getFraction();
							}
						}
					}
					info = performanceInfoDao.getPerInfoList(info);
					Integer jzz = 0;
					if (info != null) {
						if (info.getPay() != null) {
							jzz = info.getPay();
						}
					}
					result.setDefaultModel("gradeList", gradeList);

					result.setDefaultModel("dfcount", dfcount);
					result.setDefaultModel("jzz", jzz);

					// 销售主管绩效和打分
					users = userDao.getUserInfoByType(users);
					double cdl = 0.0;
					Integer shidaoAll = 0;
					Double c = 0.0;
					Double d = 0.0;
					if (users != null) {
						userns.setDate(sdate);
						List<TgUsernames> list = usernamesDao.findByExample(userns);
						if (list != null && list.size() > 0) {
							userns = list.get(0);
						}
						if (userns.getUsernames() != null && !"".equals(userns.getUsernames())) {
							String[] usernames = userns.getUsernames().split(",");
							if (usernames != null && usernames.length > 0) {
								TgUser user2 = new TgUser();
								TgUser user3 = new TgUser();
								Integer size = 0;
								for (int i = 0; i < usernames.length; i++) {
									if (usernames[i] != null && !"".equals(usernames[i])) {
										user2.setUsername(usernames[i]);
										user2.setIs_zhuanz("排除未转正");
										user3 = userDao.getUserInfoByType(user2);
										if (user3 != null) {
											size++;
											reception.setStartTime(start.getTime() / 1000);
											reception.setEndTime(end.getTime() / 1000);
											reserve.setStart(start.getTime() / 1000);
											reserve.setEnd(end.getTime() / 1000);
											reception.setUsername(usernames[i]);
											reserve.setUsername(usernames[i]);
											Double a = (double) receptionDao.getDanReceptionCount(reception);
											Double b = (double) receptionService.getZonlReceptionCount(reception);

											shidaoAll += reserveDao.getShidaoReserveCountBy(reserve);

											c += a;
											d += b;
										}
									}
								}
								if (d != 0.0 && d != 0) {
									cdl = c / d;
								} else {
									cdl = 0;
								}

								result.setDefaultModel("size", size);
								result.setDefaultModel("c", c);
								result.setDefaultModel("d", d);

								Double cdlfs = cdl / 0.35 * 40;
								if (cdlfs > 60) {
									cdlfs = 60.0;
								}
								Double daofangfs = shidaoAll / (8 * (double) size) * 40;
								if (daofangfs > 60) {
									daofangfs = 60.0;
								}

								result.setDefaultModel("cdlfs", cdlfs);
								result.setDefaultModel("daofangfs", daofangfs);
							}
						}

					}
					result.setDefaultModel("cdl", cdl);
					result.setDefaultModel("shidaoAll", shidaoAll);
					result.setDefaultModel("users", users);
				} catch (ParseException e) {
					e.printStackTrace();
				}

				result.setDefaultModel("type", type);
				result.setDefaultModel("uList", uList1);
				result.setDefaultModel("keuser", keuser);

				return result;
			}
		});
		return new ModelAndView("consultant/consultant_performance_stat", modelMap);
	}

	// 主管绩效统计下载
	@RequestMapping(value = "/consultant_performance_stat_xzgz")
	public ModelAndView consultant_performance_stat_xzgz(ModelMap modelMap, final LoginVo loginVo,
			final HttpServletRequest request, final HttpServletResponse response) throws Exception {
		modelMap = JsonExecutor.execute(logger, loginVo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String startTime = request.getParameter("sdate");

				TgUserinfo user1 = new TgUserinfo();
				user1.setType(2);
				user1.setJob("课程顾问");
				List<TgUserinfo> uList = userinfoDao.getUserInfoByUserInfo(user1);

				SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
				DecimalFormat fnum = new DecimalFormat("#.#");
				DecimalFormat fnum1 = new DecimalFormat("#.##%");
				List<JiXiao> jxlist = new ArrayList<JiXiao>();
				String sdate = "";
				try {
					Date start = null;
					Date end = null;
					List<Date> dlist = DateUtil.getMdatefandl(startTime);
					if (dlist != null && dlist.size() > 0) {
						start = dlist.get(0);
						end = dlist.get(1);
						sdate = df.format(start);
					}
					result.setDefaultModel("sdate", sdate);
					result.setDefaultModel("start", start);
					result.setDefaultModel("end", end);

					if (uList != null && uList.size() > 0) {
						TgUsernames userns = new TgUsernames();
						TgUsernames userns2 = new TgUsernames();
						TgReception reception = new TgReception();
						TgMoney mon = new TgMoney();
						TgMoney mon2 = new TgMoney();
						TgReserve reserve = new TgReserve();
						TgUsergrade usergrade = new TgUsergrade();
						TgUser user2 = new TgUser();
						TgUser user3 = new TgUser();
						for (TgUserinfo user : uList) {
							PerformanceInfo info = new PerformanceInfo();
							TgUser users = new TgUser();
							JiXiao jx = new JiXiao();
							jx.setName(user.getNickname());
							// 查询月任务量
							TgWorkload workload = new TgWorkload();
							if (startTime != null && !"".equals(startTime)) {
								workload.setMonth(df.parse(startTime).getTime() / 1000);
							} else {
								workload.setMonth(df.parse(df.format(new Date())).getTime() / 1000);
							}
							workload.setTotal_region(user.getRegion());

							Integer money = workloadDao.getWorkloadMoney(workload);
							Integer rece = workloadDao.getWorkloadRece(workload);
							Integer res = workloadDao.getWorkloadReserve(workload);
							Integer tr = workloadDao.getWorkloadTrack(workload);
							// 本月接待数据统计

							reception.setStartTime(start.getTime() / 1000);
							reception.setEndTime(end.getTime() / 1000);

							reception.setUsername(user.getUsername());
							userns.setUsername(user.getUsername());

							// 总接待
							Integer zonRece = receptionService.getZonlReceptionCount(reception);

							Integer zonChendan = receptionDao.getDanReceptionCount(reception);
							result.setDefaultModel("zonRece", zonRece);
							result.setDefaultModel("zonChendan", zonChendan);
							float sum = (float) 0;

							mon.setUsername(user.getUsername());
							mon2.setUsername(user.getUsername());

							// 新增总金额
							sum = moneyService.getZonXzMoneys(mon, mon2, start, end);

							// 本月预约数据统计
							reserve.setStart(start.getTime() / 1000);
							reserve.setEnd(end.getTime() / 1000);
							reserve.setUsername(user.getUsername());
							Integer shidao = reserveDao.getShidaoReserveCountBy(reserve);// 实到数量

							// 每月有效电话完成情况
							TgTracking tracking = new TgTracking();
							tracking.setUsername(user.getUsername());

							tracking.setStaTime(start.getTime() / 1000);
							tracking.setEnTime(end.getTime() / 1000);
							Integer cont = trackingDao.getTrackCountByType(tracking);

							float scale_money = 0;
							double scale_reception = 0;
							double scale_reserve = 0;
							float scale_track = 0;

							// 个人月度业绩完成率
							if (sum != 0 && money != null && money != 0) {
								float divider = money * 10000;
								float scale = (float) sum / divider;
								scale_money = scale;
								String sum_money = fnum1.format(scale_money);

							}
							// 当月接待成功率
							float scale1 = 0;
							if (zonChendan != 0) {
								scale1 = (float) zonChendan / zonRece;
							}
							if (scale1 != 0 && rece != null && rece != 0) {
								double sc = (double) scale1 / (rece) * 100;
								if (sc != 0 && sc > 1.5) {
									sc = (float) 1.5;
								}
								scale_reception = sc * 40;

								jx.setCjl_df(scale_reception);
								jx.setCjl_gongs(fnum.format(scale1) + "/35%*100%*40。\n当月成单数(" + zonChendan + ")/"
										+ "当月接待数总数(" + zonRece + ")");
							}
							// 当月实际到访率
							if (shidao != 0 && res != null && res != 0) {
								float rese = (float) shidao / res;
								if (rese != 0 && rese > 1.5) {
									rese = (float) 1.5;
								}
								scale_reserve = rese * 40;

								jx.setDfl_df(scale_reserve);
								jx.setDfl_gongsi("当月实际到访个数(" + shidao + ")/邀约到访任务量(" + res + ")×100％×40");
							} else {
								result.setDefaultModel("sum_reserve", 0);
							}
							// 每月有效电话完成情况
							if (cont != 0 && tr != null && tr != 0) {
								float track = (float) cont / tr;
								scale_track = track;
							}

							// 中心打分和基准值
							usergrade.setUsername(user.getUsername());
							if (startTime != null && !"".equals(startTime)) {
								usergrade.setDate(startTime);
							} else {
								usergrade.setDate(df.format(new Date()));
							}
							List<TgUsergrade> gradeList = usergradeDao.getTgUsergrade(usergrade);
							int dfcount = 0;
							String zr_msg = "";
							if (gradeList != null && gradeList.size() > 0) {
								for (TgUsergrade g : gradeList) {
									dfcount = dfcount + g.getFraction();
									zr_msg += g.getFraction() + "(" + g.getAdd_username() + "的评语：" + g.getMsg() + ")";
								}
							}
							jx.setZg_f("20");
							jx.setZr_pf(zr_msg);
							jx.setZonfen(scale_reception + scale_reserve + dfcount);

							info.setUsername(user.getUsername());
							info = performanceInfoDao.getPerInfoList(info);
							int jzz = 0;
							if (info != null) {
								if (info.getPay() != null) {
									jzz = info.getPay();
								}
							}
							jx.setJzz(jzz + "");
							jx.setMoney(jzz * (scale_reception + scale_reserve + dfcount) / 100);
							// 销售主管绩效和打分
							users.setUsername(user.getUsername());
							users = userDao.getUserInfoByType(users);
							double cdl = 0.00;
							Integer shidaoAll = 0;
							Double c = 0.0;
							Double d = 0.0;
							if (users != null) {
								userns2.setUsername(user.getUsername());
								userns2.setDate(sdate);
								List<TgUsernames> list = usernamesDao.findByExample(userns2);
								if (list != null && list.size() > 0) {
									userns = list.get(0);
								}
								if (userns.getUsernames() != null && !"".equals(userns.getUsernames())) {
									String[] usernames = userns.getUsernames().split(",");
									if (usernames != null && usernames.length > 0) {
										Integer size = 0;
										for (int i = 0; i < usernames.length; i++) {
											if (usernames[i] != null && !"".equals(usernames[i])) {
												user2.setUsername(usernames[i]);
												user2.setIs_zhuanz("排除未转正");
												user3 = userDao.getUserInfoByType(user2);
												if (user3 != null) {
													size++;
													reception.setStartTime(start.getTime() / 1000);
													reception.setEndTime(end.getTime() / 1000);
													reserve.setStart(start.getTime() / 1000);
													reserve.setEnd(end.getTime() / 1000);
													reception.setUsername(usernames[i]);
													reserve.setUsername(usernames[i]);
													Double a = (double) receptionDao.getDanReceptionCount(reception);
													Double b = (double) receptionService
															.getZonlReceptionCount(reception);

													shidaoAll += reserveDao.getShidaoReserveCountBy(reserve);

													c += a;
													d += b;
												}
											}
										}
										if (d != 0.00 && d != 0) {
											cdl = c / d;
										} else {
											cdl = 0;
										}

										result.setDefaultModel("size", size);
										result.setDefaultModel("c", c);
										result.setDefaultModel("d", d);

										Double cdlfs = cdl / 0.35 * 40;
										if (cdlfs > 60) {
											cdlfs = 60.0;
										}
										Double daofangfs = shidaoAll / (8 * (double) size) * 40;
										if (daofangfs > 60) {
											daofangfs = 60.0;
										}

										jx.setTd_cdl(cdlfs);
										jx.setGongs1(fnum.format(cdl * 100) + "%/35%*40。成单数:" + c + ",到访数:" + d);
										jx.setTd_sdl(daofangfs);
										jx.setGongs2(fnum.format(shidaoAll) + "/(8*" + size + ")*100%*40");
										jx.setFenshu(cdlfs + daofangfs + Double.valueOf(dfcount + "") + "");
										jx.setMoneys((Double
												.valueOf(fnum.format(cdlfs + daofangfs + Double.valueOf(dfcount + ""))))
												* Double.valueOf(jzz + "") / 100);
									}
								} else {
									jx.setTd_cdl(0.0);
									jx.setGongs1("0%/35%*40");
									jx.setTd_sdl(0.0);
									jx.setGongs2("0/(8*" + 0 + ")*100%*40");
									jx.setFenshu("0");
									jx.setMoneys(0.0);
								}
							} else {
								jx.setTd_cdl(0.0);
								jx.setGongs1(cdl * 100 + "%/35%*40");
								jx.setTd_sdl(0.0);
								jx.setGongs2(shidaoAll + "/(8*" + 0 + ")*100%*40");
								jx.setFenshu(0.0 + 0.0 + Double.valueOf(dfcount + "") + "");
								jx.setMoneys(0.0 + 0.0 + Double.valueOf(dfcount + "") * Double.valueOf(jzz + "") / 100);
							}
							jxlist.add(jx);
						}
					}

				} catch (ParseException e) {
					e.printStackTrace();
				}

				String name = WriterExcel.writeExcelJixiao2(jxlist, startTime);
				result.setDefaultModel("name", name);
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	// 绩效统计下载
	@RequestMapping(value = "/consultant_performance_stat_xz")
	public ModelAndView consultant_performance_stat_xz(ModelMap modelMap, final LoginVo loginVo,
			final HttpServletRequest request, final HttpServletResponse response) throws Exception {
		modelMap = JsonExecutor.execute(logger, loginVo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String startTime = request.getParameter("sdate");

				TgUserinfo user1 = new TgUserinfo();
				user1.setJob("课程顾问");
				List<TgUserinfo> uList = userinfoDao.getUserInfoByUserInfo(user1);

				SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
				DecimalFormat fnum = new DecimalFormat("#.#");
				DecimalFormat fnum1 = new DecimalFormat("#.##%");

				List<JiXiao> jxlist = new ArrayList<JiXiao>();
				String sdate = "";
				try {
					Date start = null;
					Date end = null;
					List<Date> dlist = DateUtil.getMdatefandl(startTime);
					if (dlist != null && dlist.size() > 0) {
						start = dlist.get(0);
						end = dlist.get(1);
						sdate = df.format(start);
					}
					result.setDefaultModel("sdate", sdate);
					result.setDefaultModel("start", start);
					result.setDefaultModel("end", end);

					if (uList != null && uList.size() > 0) {
						TgUsernames userns = new TgUsernames();
						TgReception reception = new TgReception();
						TgMoney mon = new TgMoney();
						TgMoney mon2 = new TgMoney();
						TgReserve reserve = new TgReserve();
						TgUsergrade usergrade = new TgUsergrade();
						for (TgUserinfo user : uList) {
							if (user.getType() == null) {

								PerformanceInfo info = new PerformanceInfo();
								JiXiao jx = new JiXiao();
								jx.setName(user.getNickname());
								// 查询月任务量
								TgWorkload workload = new TgWorkload();
								if (startTime != null && !"".equals(startTime)) {
									workload.setMonth(df.parse(startTime).getTime() / 1000);
								} else {
									workload.setMonth(df.parse(df.format(new Date())).getTime() / 1000);
								}
								workload.setTotal_region(user.getRegion());

								Integer money = workloadDao.getWorkloadMoney(workload);
								Integer rece = workloadDao.getWorkloadRece(workload);
								Integer res = workloadDao.getWorkloadReserve(workload);
								Integer tr = workloadDao.getWorkloadTrack(workload);
								// 本月接待数据统计

								reception.setStartTime(start.getTime() / 1000);
								reception.setEndTime(end.getTime() / 1000);

								reception.setUsername(user.getUsername());
								userns.setUsername(user.getUsername());

								// 总接待
								Integer zonRece = receptionService.getZonlReceptionCount(reception);

								Integer zonChendan = receptionDao.getDanReceptionCount(reception);
								result.setDefaultModel("zonRece", zonRece);
								result.setDefaultModel("zonChendan", zonChendan);
								float sum = (float) 0;

								mon.setUsername(user.getUsername());
								mon2.setUsername(user.getUsername());

								// 新增总金额
								sum = moneyService.getZonXzMoneys(mon, mon2, start, end);

								// 本月预约数据统计
								reserve.setStart(start.getTime() / 1000);
								reserve.setEnd(end.getTime() / 1000);
								reserve.setUsername(user.getUsername());
								Integer shidao = reserveDao.getShidaoReserveCountBy(reserve);// 实到数量

								// 每月有效电话完成情况
								TgTracking tracking = new TgTracking();
								tracking.setUsername(user.getUsername());

								tracking.setStaTime(start.getTime() / 1000);
								tracking.setEnTime(end.getTime() / 1000);
								Integer cont = trackingDao.getTrackCountByType(tracking);

								float scale_money = 0;
								double scale_reception = 0;
								double scale_reserve = 0;
								float scale_track = 0;

								// 个人月度业绩完成率
								if (sum != 0 && money != null && money != 0) {
									float divider = money * 10000;
									float scale = (float) sum / divider;
									scale_money = scale;
									String sum_money = fnum1.format(scale_money);

								}
								// 当月接待成功率
								float scale1 = 0;
								if (zonChendan != 0) {
									scale1 = (float) zonChendan / zonRece;
								}
								if (scale1 != 0 && rece != null && rece != 0) {
									double sc = (double) scale1 / (rece) * 100;
									if (sc != 0 && sc > 1.5) {
										sc = (float) 1.5;
									}
									scale_reception = sc * 40;

									jx.setCjl_df(scale_reception);
									jx.setCjl_gongs(fnum1.format(scale1) + "/35%*100%*40。\n当月成单数(" + zonChendan + ")/"
											+ "当月接待数总数(" + zonRece + ")");
								}
								// 当月实际到访率
								if (shidao != 0 && res != null && res != 0) {
									float rese = (float) shidao / res;
									if (rese != 0 && rese > 1.5) {
										rese = (float) 1.5;
									}
									scale_reserve = rese * 40;

									jx.setDfl_df(scale_reserve);
									jx.setDfl_gongsi("当月实际到访个数(" + shidao + ")/邀约到访任务量(" + res + ")×100％×40");
								} else {
									result.setDefaultModel("sum_reserve", 0);
								}
								// 每月有效电话完成情况
								if (cont != 0 && tr != null && tr != 0) {
									float track = (float) cont / tr;
									scale_track = track;
								}

								// 中心打分和基准值
								usergrade.setUsername(user.getUsername());
								if (startTime != null && !"".equals(startTime)) {
									usergrade.setDate(startTime);
								} else {
									usergrade.setDate(df.format(new Date()));
								}
								List<TgUsergrade> gradeList = usergradeDao.getTgUsergrade(usergrade);
								int dfcount = 0;
								String zr_msg = "";
								if (gradeList != null && gradeList.size() > 0) {
									for (TgUsergrade g : gradeList) {
										dfcount = dfcount + g.getFraction();
										zr_msg += g.getFraction() + "(" + g.getUsername() + "的评语：" + g.getMsg() + ")";
									}
								}
								jx.setZg_f("20");
								jx.setZr_pf(zr_msg);
								jx.setZonfen(scale_reception + scale_reserve + dfcount);

								info.setUsername(user.getUsername());
								info = performanceInfoDao.getPerInfoList(info);
								int jzz = 0;
								if (info != null) {
									if (info.getPay() != null) {
										jzz = info.getPay();
									}
								}
								jx.setJzz(jzz + "");
								jx.setMoney(
										jzz * (Double.valueOf(fnum.format(scale_reception + scale_reserve + dfcount)))
												/ 100);
								jxlist.add(jx);
							}
						}
					}

				} catch (Exception e) {
					e.printStackTrace();
				}

				String name = WriterExcel.writeExcelJixiao(jxlist, startTime);
				result.setDefaultModel("name", name);
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	// 模糊查找中心
	@RequestMapping(value = "/getcenter")
	public ModelAndView getcenter(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String province = request.getParameter("province");
				if (province != null && !province.equals("")) {
					TgOffice office = new TgOffice();
					office.setProvince(province.trim());
					List<TgOffice> office_List = tgOfficeDao.getOfficeName2(office);
					if (office_List != null && office_List.size() > 0) {
						office = office_List.get(0);
					}
					result.setDefaultModel("office", office);
				}
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	// 异步查找缴费方式
	@RequestMapping(value = "/getMethod")
	public ModelAndView getMethod(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String keyname = request.getParameter("keyname");
				if (keyname != null && !keyname.equals("")) {
					TgOffice office = new TgOffice();
					office.setKeyname(keyname);
					List<TgOffice> list = tgOfficeDao.findByExample(office);
					if (list != null && list.size() > 0) {
						office = list.get(0);
						TgMethod method = new TgMethod();
						method.setCenter_id(office.getId());
						List<TgMethod> mList = methodDao.findByExample(method);
						result.setDefaultModel("mList", mList);
					}
				}
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	@RequestMapping(value = "/ajaxUploadImage")
	public void ajaxUploadImage(@RequestParam("pic") MultipartFile pic, HttpServletRequest request,
			HttpServletResponse response) {
		String contextPath = "";
		try {
			// 获取输出流
			long date = new Date().getTime();
			String fileName = pic.getOriginalFilename();
			contextPath = request.getSession().getServletContext().getRealPath("/") + "uploadPic";
			File fileCatalog = new File(contextPath);
			if (!fileCatalog.exists()) {
				fileCatalog.mkdir();
			}
			OutputStream os = new FileOutputStream(contextPath + "/" + fileName);
			// 获取输入流 CommonsMultipartFile 中可以直接得到文件的流
			InputStream is = pic.getInputStream();
			int temp;
			// 一个一个字节的读取并写入
			while ((temp = is.read()) != (-1)) {
				os.write(temp);
			}
			os.flush();
			os.close();
			is.close();
			response.setCharacterEncoding("utf-8");
			PrintWriter writer = response.getWriter();
			writer.print("uploadPic/" + fileName);
		} catch (Exception e) {

		}
	}

	// 咨询老师对应的级别 p1 p2
	@RequestMapping(value = "/performance_info")
	public ModelAndView performanceInfo(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, vo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String nickname = request.getParameter("nickName");
				String dates = request.getParameter("dates");

				PerformanceInfo performanceInfo = new PerformanceInfo();
				if (!StringUtil.isEmpty(nickname)) {
					performanceInfo.setNickname(nickname);
				}
				if (!StringUtil.isEmpty(dates)) {
					performanceInfo.setDate(dates);
				}
				// 获取所有老师的级别
				Integer currPage = 1;
				if (vo.getCurrPage() != null && !"".equals(vo.getCurrPage())) {
					currPage = vo.getCurrPage();
				}
				Integer total = performanceInfoDao.getPerformanceInfoCount(performanceInfo);
				Page page = PageUtil.createPage(8, currPage, total);
				List<PerformanceInfo> list = performanceInfoDao.getPerformanceInfoList(performanceInfo, page);

				TgUserinfo user1 = new TgUserinfo();
				user1.setJob("课程顾问");
				List<TgUserinfo> uList = userinfoDao.getUserInfoByUserInfo(user1);

				List<TgLevle> levlist = levleDao.findAll(TgLevle.class);

				result.setDefaultModel("list", list);
				result.setDefaultModel("nickName", nickname);
				result.setDefaultModel("dates", dates);
				result.setDefaultModel("page", page);
				result.setDefaultModel("uList", uList);
				result.setDefaultModel("levlist", levlist);

				return result;
			}
		});
		return new ModelAndView("consultant/mark/performance_info", modelMap);
	}

	// 提交
	@RequestMapping(value = "/add_performance_info")
	public ModelAndView add_performance_info(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String id = request.getParameter("id");
				String username = request.getParameter("username");
				String levle = request.getParameter("levle");
				String date = request.getParameter("date");

				PerformanceInfo performanceInfo = new PerformanceInfo();
				performanceInfo.setUsername(username);
				performanceInfo.setDate(date);

				if (id != null && !"".equals(id)) {
					performanceInfo.setLevle(levle);
					performanceInfo.setId(Long.valueOf(id));
					performanceInfoDao.update(performanceInfo);
					result.setDefaultModel("msg", "1");
				} else {
					List<PerformanceInfo> list = performanceInfoDao.findByExample(performanceInfo);
					if (list != null && list.size() > 0) {
						result.setDefaultModel("msg", "0");
					} else {
						performanceInfo.setLevle(levle);
						performanceInfo.setCreate_time(new Date());
						performanceInfoDao.insert(performanceInfo);
						result.setDefaultModel("msg", "1");
					}
				}

				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	// 根据id查找
	@RequestMapping(value = "/get_performance_info_byid")
	public ModelAndView get_performance_info_byid(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String id = request.getParameter("id");

				if (id != null && !"".equals(id)) {
					PerformanceInfo performanceInfo = performanceInfoDao.findById(PerformanceInfo.class,
							Long.valueOf(id));
					result.setDefaultModel("performanceInfo", performanceInfo);
				}

				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	// 一键生成
	@RequestMapping(value = "/add_performance_info_all")
	public ModelAndView add_performance_info_all(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String date = request.getParameter("date");
				String date2 = request.getParameter("date2");

				PerformanceInfo performanceInfo = new PerformanceInfo();
				performanceInfo.setDate(date);
				List<PerformanceInfo> list = performanceInfoDao.findByExample(performanceInfo);
				if (list != null && list.size() > 0) {
					for (PerformanceInfo p : list) {
						PerformanceInfo performanceInfo2 = new PerformanceInfo();
						performanceInfo2.setUsername(p.getUsername());
						performanceInfo2.setDate(date2);

						List<PerformanceInfo> plist = performanceInfoDao.findByExample(performanceInfo2);
						if (plist != null && plist.size() > 0) {
							result.setDefaultModel("msg", "2");
						} else {
							performanceInfo2.setLevle(p.getLevle());
							performanceInfo2.setCreate_time(new Date());
							performanceInfoDao.insert(performanceInfo2);
							result.setDefaultModel("msg", "1");
						}

					}
				} else {
					result.setDefaultModel("msg", "0");
				}
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	@RequestMapping(value = "/markList")
	public ModelAndView salesExecutive(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, vo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				TgUser user = UserUtil.getUserFromCookies();

				String nickname2 = request.getParameter("nickName");
				String date = request.getParameter("date");

				TgUsergrade usergrade = new TgUsergrade();
				if (!StringUtil.isEmpty(nickname2)) {
					usergrade.setNickname2(nickname2);
				}
				if (!StringUtil.isEmpty(date)) {
					usergrade.setDate(date);
				}
				Integer currPage = 1;
				if (vo.getCurrPage() != null && !"".equals(vo.getCurrPage())) {
					currPage = vo.getCurrPage();
				}
				if (user.getUsername() != "system") {
					usergrade.setAdd_username(user.getUsername());
				}
				Integer total = usergradeDao.getUsergradeCount(usergrade);
				Page page = PageUtil.createPage(8, currPage, total);
				List<TgUsergrade> list = usergradeDao.getUsergradelist(usergrade, page);

				List<TgUser> ulist = new ArrayList<TgUser>();
				List<TgUser> ulist2 = new ArrayList<TgUser>();
				if (user.getUsername().equals("zhanglong") || user.getUsername().equals("system")) {
					TgUser user2 = new TgUser();
					user2.setJob("课程顾问");
					user2.setType(2);
					ulist = userDao.getUserInfoByType2(user2);
				} else {
					if (user.getType() != null && !"".equals(user.getType())) {
						if (user.getType() == 1) {
							TgUser user2 = new TgUser();
							TgUser user3 = new TgUser();
							user2.setJob("课程顾问");
							user2.setTypes("排除销售主管");
							user2.setIs_zhuanz("排除未转正");
							user2.setRegion(user.getRegion());
							ulist = userDao.getUserInfoByType2(user2);
							if (user.getUsername().equals("liuguochao")) {
								user3.setUsername("oujianting");
								ulist2 = userDao.getUserInfoByType2(user3);
							} else if (user.getUsername().equals("sheqing")) {
								user3.setUsername("lijinye");
								ulist2 = userDao.getUserInfoByType2(user3);
							}
							// ulist.addAll(ulist2);
						} else if (user.getType() == 2) {
							TgUsernames us = new TgUsernames();
							us.setDate(DateUtil.lastMonth2());
							us.setUsername(user.getUsername());
							List<TgUsernames> uslist = usernamesDao.findByExample(us);
							if (uslist != null && uslist.size() > 0) {
								us = uslist.get(0);
								if (us.getUsernames2() != null && !"".equals(us.getUsernames2())) {
									String[] users = us.getUsernames2().split(",");
									if (users != null && users.length > 0) {
										TgUser user2 = new TgUser();
										TgUser user3 = new TgUser();
										for (int i = 0; i < users.length; i++) {
											if (users[i] != null && !"".equals(users[i])) {
												user2.setUsername(users[i]);
												user2.setIs_zhuanz("排除未转正");
												user3 = userDao.getUserInfoByType(user2);
												if (user3 != null) {
													ulist.add(user3);
												}
											}
										}
									}
								}
							}
						}
					}
				}

				result.setDefaultModel("ulist", ulist);
				result.setDefaultModel("ulist2", ulist2);
				result.setDefaultModel("page", page);
				result.setDefaultModel("list", list);
				return result;
			}
		});
		return new ModelAndView("consultant/mark/markList", modelMap);
	}

	@RequestMapping(value = "/markList2")
	public ModelAndView salesExecutive2(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, vo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				TgUser user = UserUtil.getUserFromCookies();
				List<TgUser> ulist2 = new ArrayList<TgUser>();
				TgUser user3 = new TgUser();
				if (user.getUsername().equals("liuguochao")) {
					user3.setUsername("wanfei");
					ulist2 = userDao.getUserInfoByType2(user3);
				} else if (user.getUsername().equals("sheqing")) {
					user3.setUsername("wanfei");
					ulist2 = userDao.getUserInfoByType2(user3);
				}
				result.setDefaultModel("ulist2", ulist2);

				return result;
			}
		});
		return new ModelAndView("consultant/mark/addmark2", modelMap);
	}

	// 根据id获取打分
	@RequestMapping(value = "/get_mark_byid")
	public ModelAndView get_mark_byid(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String id = request.getParameter("id");
				if (id != null && !"".equals(id)) {
					TgUsergrade usergrade = usergradeDao.findById(TgUsergrade.class, Long.valueOf(id));
					result.setDefaultModel("usergrade", usergrade);
				}
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	// 打分
	@RequestMapping(value = "/add_mark")
	public ModelAndView add_mark(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String id = request.getParameter("id");
				String username = request.getParameter("username");
				String fraction = request.getParameter("fraction");
				String msg = request.getParameter("msg");

				TgUser user = UserUtil.getUserFromCookies();
				TgUsergrade usergrade = new TgUsergrade();
				if (fraction != null && !"".equals(fraction)) {
					if (id != null && !"".equals(id)) {
						usergrade.setId(Long.valueOf(id));
						usergrade.setFraction(Integer.valueOf(fraction));
						usergrade.setMsg(msg);
						usergradeDao.update(usergrade);
						result.setDefaultModel("msg", "1");
					} else {
						usergrade.setAdd_username(user.getUsername());
						usergrade.setUsername(username);
						usergrade.setDate(DateUtil.lastMonth2());
						List<TgUsergrade> list = usergradeDao.findByExample(usergrade);
						if (list != null && list.size() > 0) {
							result.setDefaultModel("msg", "0");
						} else {
							usergrade.setFraction(Integer.valueOf(fraction));
							usergrade.setMsg(msg);
							usergrade.setType(1);
							usergrade.setCreate_time(new Date());
							usergradeDao.insert(usergrade);
							result.setDefaultModel("msg", "1");
						}
					}
				}
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	private org.json.JSONObject getJsonObjInfo(String levelText, String levelValue, SimpleDateFormat sdf)
			throws JSONException {
		org.json.JSONObject jsonObject = new org.json.JSONObject();
		jsonObject.put("date", sdf.format(new Date()));
		jsonObject.put("levle", levelText);
		jsonObject.put("pay", Integer.valueOf(levelValue));
		jsonObject.put("payMax", (int) (Integer.valueOf(levelValue) * 1.4));
		return jsonObject;
	}

	/*
	 * 咨询老师推荐报名学员
	 */
	@RequestMapping(value = "/tuijianList")
	public ModelAndView tuijianList(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, vo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				TgUser user = UserUtil.getUserFromCookies();
				String stu_name = request.getParameter("stu_name");
				String currPage = request.getParameter("currPage");
				if (currPage == null || " ".equals(currPage) || "null".equals(currPage)) {
					currPage = "1";
				}
				try {
					if (stu_name != null && !"".equals(stu_name) && !"null".equals(stu_name)) {
						stu_name = URLEncoder.encode(stu_name, "utf-8");
					} else {
						stu_name = "";
					}
				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
				}
				String url = "http://www.yueqiao.org/web/teaweb/tuijianindex.json?tea_id=" + user.getId() + "&name="
						+ stu_name + "&currPage=" + currPage;
				String context = HttpUtil.doGet(url, null, "utf-8", true);
				net.sf.json.JSONArray stuList1 = JSONObject.fromObject(context).getJSONArray("list");
				// 分页
				JSONObject pageObj = new JSONObject();
				pageObj = JSONObject.fromObject(context).getJSONObject("page");

				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				List<TuiJian> list = new ArrayList<TuiJian>();
				if (stuList1 != null && stuList1.size() > 0) {
					for (int i = 0; i < stuList1.size(); i++) {
						TuiJian tuiJian = new TuiJian();
						JSONObject obj = JSONObject.fromObject(stuList1.get(i));
						try {
							tuiJian.setStu_name(obj.getString("stu_name"));
							tuiJian.setCenter(obj.getString("center"));
							tuiJian.setTuijian_type(obj.getString("tuijian_type"));
							tuiJian.setTuijian_name(obj.getString("tuijian_name"));
							tuiJian.setCy_tuijian_teacher(obj.getString("cy_tuijian_teacher"));
							tuiJian.setTjstu_time2(
									sdf.format(new Date(Long.parseLong(obj.getString("tuijian_time1")))));
							tuiJian.setXz_state(Integer.parseInt(obj.getString("xz_state")));
							tuiJian.setTuijian_kes(obj.getString("tuijian_kes"));
							tuiJian.setCp_center(obj.getString("cp_center"));
							// System.out.println(obj.getString("center"));
							tuiJian.setId(Long.valueOf(obj.getString("id")).longValue());
							list.add(tuiJian);
						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
					result.setDefaultModel("list", list);
				}
				Page page = new Page();
				if (stuList1 != null && !"".equals(stuList1) && !"null".equals(stuList1)) {
					Gson gson = new Gson();
					String s = pageObj.toString();
					page = gson.fromJson(s, Page.class);
				}
				result.setDefaultModel("page", page);
				return result;
			}
		});
		return new ModelAndView("consultant/tuijianList", modelMap);
	}

	// 填写推荐详情
	@RequestMapping(value = "/tuijiandetail")
	public ModelAndView tuijiandetail(ModelMap modelMap, final LoginVo loginVo, final HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, loginVo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String id = request.getParameter("id");
				try {
					if (id != null && !"".equals(id) && !"null".equals(id)) {
						id = URLEncoder.encode(id, "utf-8");
					} else {
						id = null;
					}
				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
				}
				String url = "http://www.yueqiao.org/web/teaweb/tuijiandetail.json?id=" + id;
				String context = HttpUtil.doGet(url, "", "utf-8", true);
				String tuijianlist = JSONObject.fromObject(context).getString("tuiJian");
				JSONObject jsStr = JSONObject.fromObject(tuijianlist);
				TuiJian tuijian = new TuiJian();
				try {
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
					tuijian.setId(Long.parseLong(jsStr.getString("id")));
					tuijian.setStu_name(jsStr.getString("stu_name"));
					tuijian.setStu_id(Long.parseLong(jsStr.getString("stu_id")));
					tuijian.setTuijian_type(jsStr.getString("tuijian_type"));
					tuijian.setMingxi(jsStr.getString("mingxi"));

					if (jsStr.getString("times") != null && !"".equals(jsStr.getString("times"))
							&& !"null".equals(jsStr.getString("times"))) {
						tuijian.setTimes(jsStr.getString("times"));
					}
					tuijian.setIs_first(jsStr.getString("is_first"));
					if (jsStr.getString("baoming_date") != null && !"".equals(jsStr.getString("baoming_date"))
							&& !"null".equals(jsStr.getString("baoming_date"))) {
						tuijian.setBaoming_date(
								sdf.parse(sdf.format(new Date(Long.parseLong(jsStr.getString("baoming_date"))))));
					}
					tuijian.setMqkeci(jsStr.getString("mqkeci"));
					tuijian.setTuijian_name(jsStr.getString("tuijian_name"));
					if (jsStr.getString("tuijian_time1") != null && !"".equals(jsStr.getString("tuijian_time1"))
							&& !"null".equals(jsStr.getString("tuijian_time1"))) {
						tuijian.setTuijian_time1(
								sdf.parse(sdf.format(new Date(Long.parseLong(jsStr.getString("tuijian_time1"))))));

					}
					tuijian.setContent1(jsStr.getString("content1"));
					if (jsStr.getString("tuijian_time2") != null && !"".equals(jsStr.getString("tuijian_time2"))
							&& !"null".equals(jsStr.getString("tuijian_time2"))) {
						tuijian.setTuijian_time2(
								sdf.parse(sdf.format(new Date(Long.parseLong(jsStr.getString("tuijian_time2"))))));
					} else {
						tuijian.setTuijian_time2(sdf.parse(sdf.format(new Date(0))));
					}
					tuijian.setContent2(jsStr.getString("content2"));
					if (jsStr.getString("tuijian_time3") != null && !"".equals(jsStr.getString("tuijian_time3"))
							&& !"null".equals(jsStr.getString("tuijian_time3"))) {
						tuijian.setTuijian_time3(
								sdf.parse(sdf.format(new Date(Long.parseLong(jsStr.getString("tuijian_time3"))))));
					} else {
						tuijian.setTuijian_time3(sdf.parse(sdf.format(new Date(0))));
					}
					tuijian.setContent3(jsStr.getString("content3"));
					tuijian.setTuijian_dj(jsStr.getString("tuijian_dj"));
					tuijian.setTuijian_kes(jsStr.getString("tuijian_kes"));
					if (jsStr.getString("tjstu_time") != null && !"".equals(jsStr.getString("tjstu_time"))
							&& !"null".equals(jsStr.getString("tjstu_time"))) {
						tuijian.setTjstu_time(
								sdf.parse(sdf.format(new Date(Long.parseLong(jsStr.getString("tjstu_time"))))));
					}
					tuijian.setGuanxi(jsStr.getString("guanxi"));
					tuijian.setIs_first(jsStr.getString("is_first"));
					tuijian.setIs_canyu(jsStr.getString("is_canyu"));
					tuijian.setUrl(jsStr.getString("url"));
					tuijian.setCy_tuijian_teacher(jsStr.getString("cy_tuijian_teacher"));

				} catch (Exception e) {
					e.printStackTrace();
				}

				result.setDefaultModel("tuijian", tuijian);
				String id1 = JSONObject.fromObject(context).getString("id");
				net.sf.json.JSONArray cenList = JSONObject.fromObject(context).getJSONArray("cenList");
				List<Center> list = new ArrayList<Center>();
				if (cenList != null && cenList.size() > 0) {
					for (int i = 0; i < cenList.size(); i++) {
						Center center = new Center();
						JSONObject fff = JSONObject.fromObject(cenList.get(i));
						center.setCenter(fff.getString("center"));
						center.setId(fff.getLong("id"));
						list.add(center);
					}
					result.setDefaultModel("cenList", list);
				}
				result.setDefaultModel("id", id1);
				return result;
			}
		});
		return new ModelAndView("consultant/tuijiandetail", modelMap);
	}

	// 保存推荐详情
	@RequestMapping(value = "/updatetuijiansh")
	public ModelAndView updatetuijiansh(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String id = request.getParameter("id");
				String zs_msg = request.getParameter("zs_msg");
				String zs_jiaofei_date = request.getParameter("zs_jiaofei_date");
				String zs_jiaofei_jine = request.getParameter("zs_jiaofei_jine");
				String zs_ke_detail = request.getParameter("zs_ke_detail");
				String zs_tuijian_zj = request.getParameter("zs_tuijian_zj");
				String cp_date = request.getParameter("cp_date");
				String cp_center = request.getParameter("cp_center");
				try {
					if (id != null && !"".equals(id) && !"null".equals(id)) {
						id = URLEncoder.encode(id, "utf-8");
					} else {
						id = "";
					}
					if (zs_msg != null && !"".equals(zs_msg) && !"null".equals(zs_msg)) {
						zs_msg = URLEncoder.encode(zs_msg, "utf-8");
					} else {
						zs_msg = "";
					}
					if (zs_jiaofei_date != null && !"".equals(zs_jiaofei_date) && !"null".equals(zs_jiaofei_date)) {
						zs_jiaofei_date = URLEncoder.encode(zs_jiaofei_date, "utf-8");
					} else {
						zs_jiaofei_date = "";
					}
					if (zs_jiaofei_jine != null && !"".equals(zs_jiaofei_jine) && !"null".equals(zs_jiaofei_jine)) {
						zs_jiaofei_jine = URLEncoder.encode(zs_jiaofei_jine, "utf-8");
					} else {
						zs_jiaofei_jine = "";
					}
					if (zs_ke_detail != null && !"".equals(zs_ke_detail) && !"null".equals(zs_ke_detail)) {
						zs_ke_detail = URLEncoder.encode(zs_ke_detail, "utf-8");
					} else {
						zs_ke_detail = "";
					}
					if (zs_tuijian_zj != null && !"".equals(zs_tuijian_zj) && !"null".equals(zs_tuijian_zj)) {
						zs_tuijian_zj = URLEncoder.encode(zs_tuijian_zj, "utf-8");
					} else {
						zs_tuijian_zj = "";
					}
					if (cp_date != null && !"".equals(cp_date) && !"null".equals(cp_date)) {
						cp_date = URLEncoder.encode(cp_date, "utf-8");
					} else {
						cp_date = "";
					}
					if (cp_center != null && !"".equals(cp_center) && !"null".equals(cp_center)) {
						cp_center = URLEncoder.encode(cp_center, "utf-8");
					} else {
						cp_center = "";
					}

				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
				}
				result.setDefaultModel("msg", "0");
				String url = "http://www.yueqiao.org/web/teaweb/updatetuijiansh.json?id=" + id + "&zs_msg=" + zs_msg
						+ "&zs_jiaofei_date=" + zs_jiaofei_date + "&zs_jiaofei_jine=" + zs_jiaofei_jine
						+ "&zs_ke_detail=" + zs_ke_detail + "&zs_tuijian_zj=" + zs_tuijian_zj + "&cp_date=" + cp_date
						+ "&cp_center=" + cp_center;
				HttpUtil.doGet(url, "", "utf-8", true);
				result.setDefaultModel("msg", "1");
				return result;

			}
		});
		return new ModelAndView("", modelMap);
	}

	// 进入审核页面
	@RequestMapping(value = "/tuijiansh")
	public ModelAndView tuijiansh(ModelMap modelMap, final LoginVo loginVo, final HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, loginVo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String id = request.getParameter("id");
				TgUser user = UserUtil.getUserFromCookies();
				try {
					if (id != null && !"".equals(id) && !"null".equals(id)) {
						id = URLEncoder.encode(id, "utf-8");
					} else {
						id = "";
					}
				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
				}
				String url = "http://www.yueqiao.org/web/teaweb/tuijiandetail.json?id=" + id;
				String context = HttpUtil.doGet(url, "", "utf-8", true);
				String tuijianlist = JSONObject.fromObject(context).getString("tuiJian");
				JSONObject jsStr = JSONObject.fromObject(tuijianlist);
				TuiJian tuijian = new TuiJian();
				try {
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
					tuijian.setId(Long.parseLong(jsStr.getString("id")));
					tuijian.setStu_name(jsStr.getString("stu_name"));
					tuijian.setTuijian_type(jsStr.getString("tuijian_type"));
					tuijian.setMingxi(jsStr.getString("mingxi"));

					if (jsStr.getString("times") != null && !"".equals(jsStr.getString("times"))
							&& !"null".equals(jsStr.getString("times"))) {
						tuijian.setTimes(jsStr.getString("times"));
					}
					tuijian.setIs_first(jsStr.getString("is_first"));
					if (jsStr.getString("baoming_date") != null && !"".equals(jsStr.getString("baoming_date"))
							&& !"null".equals(jsStr.getString("baoming_date"))) {
						tuijian.setBaoming_date(
								sdf.parse(sdf.format(new Date(Long.parseLong(jsStr.getString("baoming_date"))))));
					}
					tuijian.setMqkeci(jsStr.getString("mqkeci"));
					tuijian.setTuijian_name(jsStr.getString("tuijian_name"));
					if (jsStr.getString("tuijian_time1") != null && !"".equals(jsStr.getString("tuijian_time1"))
							&& !"null".equals(jsStr.getString("tuijian_time1"))) {
						tuijian.setTuijian_time1(
								sdf.parse(sdf.format(new Date(Long.parseLong(jsStr.getString("tuijian_time1"))))));

					}
					tuijian.setContent1(jsStr.getString("content1"));
					if (jsStr.getString("tuijian_time2") != null && !"".equals(jsStr.getString("tuijian_time2"))
							&& !"null".equals(jsStr.getString("tuijian_time2"))) {
						tuijian.setTuijian_time2(
								sdf.parse(sdf.format(new Date(Long.parseLong(jsStr.getString("tuijian_time2"))))));
					} else {
						tuijian.setTuijian_time2(
								sdf.parse(sdf.format(new Date(Long.parseLong(jsStr.getString("tuijian_time1"))))));
					}
					tuijian.setContent2(jsStr.getString("content2"));
					if (jsStr.getString("tuijian_time3") != null && !"".equals(jsStr.getString("tuijian_time3"))
							&& !"null".equals(jsStr.getString("tuijian_time3"))) {
						tuijian.setTuijian_time3(
								sdf.parse(sdf.format(new Date(Long.parseLong(jsStr.getString("tuijian_time3"))))));
					} else {
						tuijian.setTuijian_time3(
								sdf.parse(sdf.format(new Date(Long.parseLong(jsStr.getString("tuijian_time1"))))));
					}
					tuijian.setContent3(jsStr.getString("content3"));
					tuijian.setTuijian_dj(jsStr.getString("tuijian_dj"));
					tuijian.setTuijian_kes(jsStr.getString("tuijian_kes"));
					if (jsStr.getString("tjstu_time") != null && !"".equals(jsStr.getString("tjstu_time"))
							&& !"null".equals(jsStr.getString("tjstu_time"))) {
						tuijian.setTjstu_time(
								sdf.parse(sdf.format(new Date(Long.parseLong(jsStr.getString("tjstu_time"))))));
					}
					tuijian.setGuanxi(jsStr.getString("guanxi"));
					tuijian.setIs_first(jsStr.getString("is_first"));
					tuijian.setIs_canyu(jsStr.getString("is_canyu"));
					tuijian.setUrl(jsStr.getString("url"));
					tuijian.setCy_tuijian_teacher(jsStr.getString("cy_tuijian_teacher"));
					if (jsStr.getString("cp_date") != null && !"".equals(jsStr.getString("cp_date"))
							&& !"null".equals(jsStr.getString("cp_date"))) {
						// System.out.println(sdf.format(new
						// Date(Long.parseLong(jsStr.getString("cp_date")))));
						tuijian.setCp_date(sdf.parse(sdf.format(new Date(Long.parseLong(jsStr.getString("cp_date"))))));
					}
					if (jsStr.getString("jiaofei_date") != null && !"".equals(jsStr.getString("jiaofei_date"))
							&& !"null".equals(jsStr.getString("jiaofei_date"))) {
						// System.out.println(sdf.format(new
						// Date(Long.parseLong(jsStr.getString("jiaofei_date")))));
						tuijian.setJiaofei_date(
								sdf.parse(sdf.format(new Date(Long.parseLong(jsStr.getString("jiaofei_date"))))));
					}
					tuijian.setJiaofei_jine(jsStr.getString("jiaofei_jine"));
					tuijian.setKe_detail(jsStr.getString("ke_detail"));
					tuijian.setTuijian_zj(jsStr.getString("tuijian_zj"));
					tuijian.setZs_msg(jsStr.getString("zs_msg"));
					tuijian.setXz_state(Integer.parseInt(jsStr.getString("xz_state")));
					tuijian.setCp_center(jsStr.getString("cp_center"));
				} catch (Exception e) {
					e.printStackTrace();
				}

				String id1 = JSONObject.fromObject(context).getString("id");
				net.sf.json.JSONArray cenList = JSONObject.fromObject(context).getJSONArray("cenList");
				List<Center> list = new ArrayList<Center>();
				if (cenList != null && cenList.size() > 0) {
					for (int i = 0; i < cenList.size(); i++) {
						Center center = new Center();
						JSONObject fff = JSONObject.fromObject(cenList.get(i));
						center.setCenter(fff.getString("center"));
						center.setId(fff.getLong("id"));
						list.add(center);

					}
					result.setDefaultModel("cenList", list);
				}
				for (int i = 0; i < list.size(); i++) {
					Long id2 = list.get(i).getId();
					if (tuijian.getCp_center() != null && !"null".equals(tuijian.getCp_center())
							&& Long.parseLong(tuijian.getCp_center()) == (id2)) {
						tuijian.setCp_center(list.get(i).getCenter());
						break;
					}
				}
				result.setDefaultModel("userId", user.getId());
				result.setDefaultModel("tuijian", tuijian);
				result.setDefaultModel("id", id1);
				return result;
			}
		});
		return new ModelAndView("consultant/tuijiansh", modelMap);
	}

	// 保存推荐学员的审核
	@RequestMapping(value = "/save_sh")
	public ModelAndView save_sh(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			HttpServletResponse response) throws BaseException {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String id = request.getParameter("id");
				String xz_state = request.getParameter("xz_state");
				String zs_msg = request.getParameter("zs_msg");

				try {
					if (id != null && !"".equals(id) && !"null".equals(id)) {
						id = URLEncoder.encode(id, "utf-8");
					} else {
						id = "";
					}
					if (xz_state != null && !"".equals(xz_state) && !"null".equals(xz_state)) {
						xz_state = URLEncoder.encode(xz_state, "utf-8");
					} else {
						xz_state = "";
					}
					if (zs_msg != null && !"".equals(zs_msg) && !"null".equals(zs_msg)) {
						zs_msg = URLEncoder.encode(zs_msg, "utf-8");
					} else {
						zs_msg = "";
					}

				} catch (UnsupportedEncodingException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				String url = "http://www.yueqiao.org/web/teaweb/updatetuijiansh.json?id=" + id + "&xz_state=" + xz_state
						+ "&zs_msg=" + zs_msg;
				String context = HttpUtil.doGet(url, "", "utf-8", true);
				result.setDefaultModel("msg", "1");
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	// 进入推荐登记
	@RequestMapping(value = "/tuijian_student_add")
	public ModelAndView tuijian_view(ModelMap modelMap, final LoginVo loginVo, final HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, loginVo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String id = request.getParameter("id");
				String name = request.getParameter("stu_name");
				TgUser user = UserUtil.getUserFromCookies();
				String center2 = user.getRegions();
				try {
					center2 = URLEncoder.encode(center2, "utf-8");
				} catch (UnsupportedEncodingException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				String url = "http://www.yueqiao.org/web/teaweb/getStudentByCenter.json?center=" + center2;
				String context = HttpUtil.doGet(url, "", "utf-8", true);
				net.sf.json.JSONArray list = JSONObject.fromObject(context).getJSONArray("list");

				String center = user.getRegions().substring(0, 2);
				try {
					center = URLEncoder.encode(center, "utf-8");
				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();

				}

				String url2 = "http://www.yueqiao.org/web/teaweb/goToTuijian.json?center=" + center;
				String context2 = HttpUtil.doGet(url2, "", "utf-8", true);

				JSONObject fromObject = JSONObject.fromObject(context2);
				Object object = fromObject.get("teaList");
				List list1 = (List) fromObject.get("teaList");

				result.setDefaultModel("list", list);
				result.setDefaultModel("teaList", list1);
				return result;
			}
		});
		return new ModelAndView("consultant/tuijian_student_add", modelMap);
	}

	// 根据名字查找学员
	@RequestMapping(value = "/getstudentByname2")
	public ModelAndView getstudentByname2(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String nickname = request.getParameter("nickname");
				try {
					nickname = URLEncoder.encode(nickname, "utf-8");
				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
				}
				String url = "http://www.yueqiao.org/web/teaweb/getstudentByname.json?name=" + nickname;
				String context = HttpUtil.doGet(url, "", "utf-8", true);
				String list = JSONObject.fromObject(context).getString("list");
				Object id = JSONObject.fromObject(list).getInt("id");
				Object name = JSONObject.fromObject(list).getString("name");
				// System.out.println(id.toString()+name.toString());
				TgUser user = new TgUser();
				user.setId((Integer) id);
				user.setNickname((String) name);
				result.setDefaultModel("user", user);

				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	// 保存被推荐学员
	@RequestMapping(value = "/tuijian_student_save")
	public ModelAndView tuijian_save(ModelMap modelMap, final LoginVo loginVo, final HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		modelMap = JsonExecutor.execute(logger, loginVo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String id = request.getParameter("id");
				String stu_id = request.getParameter("stu_id");
				String stu_name = request.getParameter("stu_name");
				TgUser teacher = UserUtil.getUserFromCookies();
				String center = teacher.getRegions();
				String tea_id = teacher.getId().toString();
				String tuijian_type = request.getParameter("tuijian_type");
				String is_first = request.getParameter("is_first");
				String times = request.getParameter("cishu");
				String mingxi = request.getParameter("mingxi");
				String baoming_date = request.getParameter("baoming_date");

				String tuijian_name = request.getParameter("tuijian_name");
				String mqkeci = request.getParameter("mqkeci");
				String tuijian_time1 = request.getParameter("tuijian_time1");
				String tuijian_time2 = request.getParameter("tuijian_time2");
				String tuijian_time3 = request.getParameter("tuijian_time3");
				String content1 = request.getParameter("content1");
				String content2 = request.getParameter("content2");
				String content3 = request.getParameter("content3");

				String tuijian_dj = request.getParameter("tuijian_dj");
				String tuijian_kes = request.getParameter("tuijian_kes");
				String tjstu_time = request.getParameter("tjstu_time");
				String guanxi = request.getParameter("guanxi");
				String is_canyu = request.getParameter("is_canyu");
				String tuijian_tea = request.getParameter("tuijian_tea");
				String url1 = request.getParameter("url");
				String data_url = request.getParameter("data_url");

				try {
					if (id != null && !"".equals(id) && !"null".equals(id)) {
						id = URLEncoder.encode(id, "utf-8");
					} else {
						id = "";
					}
					if (stu_id != null && !"".equals(stu_id) && !"null".equals(stu_id)) {
						stu_id = URLEncoder.encode(stu_id, "utf-8");
					} else {
						stu_id = "";
					}
					if (stu_name != null && !"".equals(stu_name) && !"null".equals(stu_name)) {
						stu_name = URLEncoder.encode(stu_name, "utf-8");
					} else {
						stu_name = "";
					}
					if (center != null && !"".equals(center) && !"null".equals(center)) {
						center = URLEncoder.encode(center, "utf-8");
					} else {
						center = "";
					}
					if (tea_id != null && !"".equals(tea_id) && !"null".equals(tea_id)) {
						tea_id = URLEncoder.encode(tea_id, "utf-8");
					} else {
						tea_id = "";
					}
					if (tuijian_type != null && !"".equals(tuijian_type) && !"null".equals(tuijian_type)) {
						tuijian_type = URLEncoder.encode(tuijian_type, "utf-8");
					} else {
						tuijian_type = "";
					}
					if (is_first != null && !"".equals(is_first) && !"null".equals(is_first)) {
						is_first = URLEncoder.encode(is_first, "utf-8");
					} else {
						is_first = "";
					}
					if (times != null && !"".equals(times) && !"null".equals(times)) {
						times = URLEncoder.encode(times, "utf-8");
					} else {
						times = "";
					}
					if (mingxi != null && !"".equals(mingxi) && !"null".equals(mingxi)) {
						mingxi = URLEncoder.encode(mingxi, "utf-8");
					} else {
						mingxi = "";
					}
					if (baoming_date != null && !"".equals(baoming_date) && !"null".equals(baoming_date)) {
						baoming_date = URLEncoder.encode(baoming_date, "utf-8");
					} else {
						baoming_date = "";
					}
					if (tuijian_name != null && !"".equals(tuijian_name) && !"null".equals(tuijian_name)) {
						tuijian_name = URLEncoder.encode(tuijian_name, "utf-8");
					} else {
						tuijian_name = "";
					}
					if (mqkeci != null && !"".equals(mqkeci) && !"null".equals(mqkeci)) {
						mqkeci = URLEncoder.encode(mqkeci, "utf-8");
					} else {
						mqkeci = "";
					}
					if (tuijian_time1 != null && !"".equals(tuijian_time1) && !"null".equals(tuijian_time1)) {
						tuijian_time1 = URLEncoder.encode(tuijian_time1, "utf-8");
					} else {
						tuijian_time1 = "";
					}
					if (tuijian_time2 != null && !"".equals(tuijian_time2) && !"null".equals(tuijian_time2)) {
						tuijian_time2 = URLEncoder.encode(tuijian_time2, "utf-8");
					} else {
						tuijian_time2 = "";
					}
					if (tuijian_time3 != null && !"".equals(tuijian_time3) && !"null".equals(tuijian_time3)) {
						tuijian_time3 = URLEncoder.encode(tuijian_time3, "utf-8");
					} else {
						tuijian_time3 = "";
					}
					if (content1 != null && !"".equals(content1) && !"null".equals(content1)) {
						content1 = URLEncoder.encode(content1, "utf-8");
					} else {
						content1 = "";
					}
					if (content2 != null && !"".equals(content2) && !"null".equals(content2)) {
						content2 = URLEncoder.encode(content2, "utf-8");
					} else {
						content2 = "";
					}
					if (content3 != null && !"".equals(content3) && !"null".equals(content3)) {
						content3 = URLEncoder.encode(content3, "utf-8");
					} else {
						content3 = "";
					}
					if (tuijian_dj != null && !"".equals(tuijian_dj) && !"null".equals(tuijian_dj)) {
						tuijian_dj = URLEncoder.encode(tuijian_dj, "utf-8");
					} else {
						tuijian_dj = "";
					}
					if (tuijian_kes != null && !"".equals(tuijian_kes) && !"null".equals(tuijian_kes)) {
						tuijian_kes = URLEncoder.encode(tuijian_kes, "utf-8");
					} else {
						tuijian_kes = "";
					}
					if (tjstu_time != null && !"".equals(tjstu_time) && !"null".equals(tjstu_time)) {
						tjstu_time = URLEncoder.encode(tjstu_time, "utf-8");
					} else {
						tjstu_time = "";
					}
					if (guanxi != null && !"".equals(guanxi) && !"null".equals(guanxi)) {
						guanxi = URLEncoder.encode(guanxi, "utf-8");
					} else {
						guanxi = "";
					}
					if (is_canyu != null && !"".equals(is_canyu) && !"null".equals(is_canyu)) {
						is_canyu = URLEncoder.encode(is_canyu, "utf-8");
					} else {
						is_canyu = "";
					}
					if (tuijian_tea != null && !"".equals(tuijian_tea) && !"null".equals(tuijian_tea)) {
						tuijian_tea = URLEncoder.encode(tuijian_tea, "utf-8");
					} else {
						tuijian_tea = "";
					}
					if (url1 != null && !"".equals(url1) && !"null".equals(url1)) {
						url1 = URLEncoder.encode(url1, "utf-8");
					} else {
						url1 = "";
					}
					if (MathUtil.isNotEmpty(data_url)) {
						data_url = URLEncoder.encode(data_url, "utf-8");
					} else {
						data_url = "";
					}
				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
				}
				result.setDefaultModel("msg", "0");
				String url = "http://www.yueqiao.org/web/teaweb/savetuijian.json?tea_id=" + tea_id + "&id=" + id
						+ "&tuijian_type=" + tuijian_type + "&mingxi=" + mingxi + "&is_first=" + is_first
						+ "&baoming_date=" + baoming_date + "&stu_id=" + stu_id + "&stu_name=" + stu_name + "&times="
						+ times + "&tuijian_name=" + tuijian_name + "&mqkeci=" + mqkeci + "&content3=" + content3
						+ "&tuijian_time1=" + tuijian_time1 + "&tuijian_time2=" + tuijian_time2 + "&tuijian_time3="
						+ tuijian_time3 + "&content1=" + content1 + "&content2=" + content2 + "&center=" + center
						+ "&tuijian_dj=" + tuijian_dj + "&tuijian_kes=" + tuijian_kes + "&tjstu_time=" + tjstu_time
						+ "&guanxi=" + guanxi + "&is_canyu=" + is_canyu + "&tuijian_tea=" + tuijian_tea + "&url=" + url1
						+ "&data_url=" + data_url;
				HttpUtil.doGet(url, "", "utf-8", true);
				result.setDefaultModel("msg", "1");
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	// 删除推荐学员
	@RequestMapping(value = "/deletetuijian")
	public ModelAndView deletetuijian(ModelMap modelMap, final LoginVo loginVo, final HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		modelMap = JsonExecutor.execute(logger, loginVo, new JsonBiz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String id = request.getParameter("id");
				try {
					if (id != null && !"".equals(id) && !"null".equals(id)) {
						id = URLEncoder.encode(id, "utf-8");
					} else {
						id = "";
					}
					result.setDefaultModel("msg", "0");
					String url = "http://www.yueqiao.org/web/teaweb/deletetuijian.json?ids=" + id;
					HttpUtil.doGet(url, "", "utf-8", true);
					result.setDefaultModel("msg", "1");
				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
				}
				return result;
			}
		});
		return new ModelAndView("", modelMap);
	}

	// 团队绩效
	@RequestMapping(value = "/tuandui_jx")
	public ModelAndView tuanduijixiao(ModelMap modelMap, final LoginVo loginVo, final HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, loginVo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String startdate = request.getParameter("sdate");
				String keuser = request.getParameter("keuser");

				TgUser user = UserUtil.getUserFromCookies();
				SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
				SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd");
				String sdate = "";
				String startTime = "";
				String endTime = "";

				try {
					Date start = null;
					Date end = null;
					List<Date> dlist = DateUtil.getMdatefandl(startdate);
					if (dlist != null && dlist.size() > 0) {
						start = dlist.get(0);
						end = dlist.get(1);
						sdate = df.format(start);
						startTime = df1.format(start);
						endTime = df1.format(end);

					}
					result.setDefaultModel("sdate", sdate);
					result.setDefaultModel("start", start);
					result.setDefaultModel("end", end);
				} catch (Exception e) {
					e.printStackTrace();
				}
				/*
				 * TgUserinfo user1 = new TgUserinfo(); user1.setJob("课程顾问");
				 * List<TgUserinfo> uList =
				 * userinfoDao.getUserInfoByUserInfo(user1);
				 */
				TgUsernames us1 = new TgUsernames();
				if (sdate != null && !"".equals(sdate)) {
					us1.setDate(sdate);
				}
				Integer currPage = loginVo.getCurrPage() == null ? 1 : loginVo.getCurrPage();
				Integer total = usernamesDao.getUsernamesCountByType(us1);
				Page page = PageUtil.createPage(10, currPage, total);
				List<TgUsernames> uList = usernamesDao.getUsernamesByType(us1, page);

				TgUsernames us = new TgUsernames();
				if (sdate != null && !"".equals(sdate)) {
					us.setDate(sdate);
				}

				us.setUsername(keuser);
				List<TgUsernames> uslist = usernamesDao.findByExample(us);
				if (uslist != null && uslist.size() > 0) {
					us = uslist.get(0);
					if (us.getUsernames2() != null && !"".equals(us.getUsernames2())) {
						String[] users = us.getUsernames().split(",");
						if (users != null && users.length > 0) {
							TgUser user2 = new TgUser();
							// 课程数
							Double kc_count = 0.0;
							// 提点
							Double tidian = 0.0;
							// 业绩
							float yeji = 0.0f;
							for (int i = 0; i < users.length; i++) {
								if (users[i] != null && !"".equals(users[i])) {
									user2.setUsername(users[i]);
									TgMoney money = new TgMoney();
									money.setUsername(users[i]);
									money.setStartTime(startTime);
									money.setEndTime(endTime);
									List<TgMoney> moneys = moneyDao.getMoneysTuanduikcByType(money);
									if (moneys != null && moneys.size() > 0) {
										for (int j = 0; j < moneys.size(); j++) {
											TgMoney mon = moneys.get(j);
											// 课程数tmp
											Double kc_count_tmp = 0.0;

											if (mon.getPra_type() == 1) {

												kc_count_tmp = ((mon.getTimes() / 120) * 1.0);
											} else if (mon.getPra_type() == 2) {
												kc_count_tmp = ((mon.getTimes() / 60) * 1.0);
											} else if (mon.getPra_type() == 3) {
												kc_count_tmp = ((mon.getTimes() / 45) * 1.0);
											} else if (mon.getPra_type() == 4) {
												if (mon.getTimes() <= 30) {// 体验包

													kc_count_tmp = 0.5;

												} else {

													kc_count_tmp = ((mon.getTimes() / 60) * 1.0);
												}
											} else if (mon.getPra_type() == 8) {
												kc_count_tmp = 0.25;
											}

											kc_count += kc_count_tmp;
											if (mon.getFp_moneys() != null && !"".equals(mon.getFp_moneys())) {
												yeji += mon.getFp_moneys();

											}
										}

									}

								}
							}
							// 提点
							if (kc_count < 3.5) {
								tidian = 0.5;
							} else if (kc_count >= 3.5 && kc_count < 4.5) {
								tidian = 0.75;
							} else if (kc_count >= 4.5 && kc_count < 6) {
								tidian = 1.0;
							} else if (kc_count >= 8 && kc_count < 10) {
								tidian = 1.5;
							} else if (kc_count >= 10 && kc_count < 11) {
								tidian = 1.75;
							} else if (kc_count >= 11 && kc_count < 12) {
								tidian = 2.0;
							} else if (kc_count >= 12) {
								tidian = 2.5;
							}
							Double jiangjin = yeji * tidian / 100.0;
							result.setDefaultModel("tidian", tidian);
							result.setDefaultModel("yeji", yeji);
							result.setDefaultModel("uList", uList);
							result.setDefaultModel("keuser", keuser);
							result.setDefaultModel("jiangjin", jiangjin);
							result.setDefaultModel("kc_count", kc_count);
						}
					}
				}

				return result;
			}
		});
		return new ModelAndView("consultant/consultant_tuandui_jx", modelMap);
	}

	// 培养奖金
	@RequestMapping(value = "/peiyang_jj")
	public ModelAndView peiyang_jj(ModelMap modelMap, final LoginVo loginVo, final HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, loginVo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				TgUserinfo user1 = new TgUserinfo();
				user1.setJob("课程顾问");
				List<TgUserinfo> uList = userinfoDao.getUserInfoByUserInfo(user1);
				List<TgUserinfo> ulist1 = new ArrayList<TgUserinfo>();
				for (int i = 0; i < uList.size(); i++) {
					TgUserinfo user2 = uList.get(i);
					SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
					if (user2.getEntryday() != null && user2.getZhuanz_date() != null) {
						String startDate = format.format(new Date((long) user2.getEntryday() * 1000));

						try {
							String ding = "";
							String ding1 = "";// 转正后一个月
							String ding2 = "";// 转正后两个月
							String ding3 = "";// 转正后三个月
							String ding4 = "";// 转正后四个月
							Integer jiangjin = 0;

							TgQuit quit = new TgQuit();
							quit.setLogin_name(user2.getUsername());
							Page page = PageUtil.createPage(10, 1, 10);
							List<TgQuit> list = quitDao.getQuitByType(quit, page);
							// 计算离职距离转正日期
							if (list.get(0) != null) {
								TgQuit quit1 = list.get(0);
								quit1.getInduction_time();

								Date dingDate1 = DateUtil.getBeforeMonthDate(quit1.getInduction_time(), 1);
								Date dingDate2 = DateUtil.getBeforeMonthDate(quit1.getInduction_time(), 2);
								Date dingDate3 = DateUtil.getBeforeMonthDate(quit1.getInduction_time(), 3);
								Date dingDate4 = DateUtil.getBeforeMonthDate(quit1.getInduction_time(), 4);
								ding1 = format.format(dingDate1);
								ding2 = format.format(dingDate2);
								ding3 = format.format(dingDate3);
								ding4 = format.format(dingDate4);

							}
							// 获取转正日期前3个月日期
							if (user2.getZhuanz_date() != null && !"".equals(user2.getZhuanz_date())) {
								Date dingDate = DateUtil.getBeforeMonthDate(format.parse(user2.getZhuanz_date()), 3);
								ding = format.format(dingDate);// 前推三个月
							}
							// 转正日期和入职日期作比较
							if (user2.getEntryday() != null && user2.getEntryday() != 0) {
								String entry = format.format(new Date(user2.getEntryday()));
								boolean isbefore = DateUtil.compareDate(ding, entry);// 是否是三个月后转正
								int dd = 0;
								try {
									dd = DateUtil.getMonthSpace("2017-05-08", "2017-07-01");
								} catch (Exception e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}
								if (isbefore) {
									jiangjin = 500;

									if (user2.getZhuanz_date() != null && !"".equals(user2.getZhuanz_date())) {
										if (ding1 != null && !"".equals(ding1)) {
											boolean isbefore1 = DateUtil.compareDate(ding1, user2.getZhuanz_date());// 是否是一个月转正离职

											if (isbefore1) {
												jiangjin = jiangjin - 280;
											}

										} else if (ding2 != null && !"".equals(ding2)) {
											boolean isbefore2 = DateUtil.compareDate(ding2, user2.getZhuanz_date());// 是否是2个月转正离职

											if (isbefore2) {
												jiangjin = jiangjin - 250;
											}
										} else if (ding3 != null && !"".equals(ding3)) {
											boolean isbefore3 = DateUtil.compareDate(ding3, user2.getZhuanz_date());// 是否是3个月转正离职

											if (isbefore3) {
												jiangjin = jiangjin - 200;
											}
										} else if (ding4 != null && !"".equals(ding4)) {
											boolean isbefore4 = DateUtil.compareDate(ding4, user2.getZhuanz_date());// 是否是3个月转正离职

											if (isbefore4) {
												jiangjin = jiangjin - 130;
											}
										}

									}

								} else {

									jiangjin = 300;
									if (user2.getZhuanz_date() != null && !"".equals(user2.getZhuanz_date())) {
										if (ding1 != null && !"".equals(ding1)) {
											boolean isbefore1 = DateUtil.compareDate(ding1, user2.getZhuanz_date());// 是否是一个月转正离职

											if (isbefore1) {
												jiangjin = jiangjin - 350;
											}

										} else if (ding2 != null && !"".equals(ding2)) {
											boolean isbefore2 = DateUtil.compareDate(ding2, user2.getZhuanz_date());// 是否是2个月转正离职

											if (isbefore2) {
												jiangjin = jiangjin - 320;
											}
										} else if (ding3 != null && !"".equals(ding3)) {
											boolean isbefore3 = DateUtil.compareDate(ding3, user2.getZhuanz_date());// 是否是3个月转正离职

											if (isbefore3) {
												jiangjin = jiangjin - 270;
											}
										} else if (ding4 != null && !"".equals(ding4)) {
											boolean isbefore4 = DateUtil.compareDate(ding4, user2.getZhuanz_date());// 是否是4个月转正离职

											if (isbefore4) {
												jiangjin = jiangjin - 200;
											}
										}

									}

								}
								user2.setJiangjin(jiangjin);
								ulist1.add(user2);
								System.out.println("———————————df—————————————奖金" + "--" + dd + jiangjin + "--" + entry
										+ ding + user2.getNickname());
							}

						} catch (ParseException e) {
							e.printStackTrace();
						}

					}

				}
				result.setDefaultModel("ulist1", ulist1);

				return result;
			}
		});
		return new ModelAndView("consultant/consultant_tuandui_jx", modelMap);
	}

	// 培育奖金
	@RequestMapping(value = "/peiyu_jj")
	public ModelAndView peiyu_jj(ModelMap modelMap, final LoginVo loginVo, final HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, loginVo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				String core = request.getParameter("core");
				String consult = request.getParameter("consult");
				core = "上海东方路";
				consult = "gongqiwen";

				TgTeaching tgTeaching = new TgTeaching();
				if (core != null && !"".equals(core) && !"null".equals(core)) {
					tgTeaching.setCore(core);
					result.setDefaultModel("core", core);
				}
				if (consult != null && !"".equals(consult) && !"null".equals(consult)) {
					tgTeaching.setConsult(consult);
					result.setDefaultModel("consult", consult);
				}
				Integer total = teachingDao.getTgTeachingCount(tgTeaching);
				Page page = PageUtil.createPage(50, 1, total);
				List<TgTeaching> list = teachingDao.getTgTeachingList(tgTeaching, page);
				result.setDefaultModel("num", total);
				result.setDefaultModel("page", page);
				result.setDefaultModel("list", list);
				// 遍历带教老师所带的老师
				for (TgTeaching tgTeaching2 : list) {
					TgUserinfo userinfo = new TgUserinfo();
					userinfo.setUsername(tgTeaching2.getTeaching());
					userinfo.setLock("0");
					List<TgUserinfo> uList = userinfoDao.getUserInfoByUserInfo(userinfo);
					userinfo = uList.get(0);
					if (userinfo.getZhuanz_date() != null && !"".equals(userinfo.getZhuanz_date())) {
						// 所带老师转正的日期
						result.setDefaultModel("zhuanz", userinfo.getZhuanz_date());

					}

				}

				return result;
			}
		});
		return new ModelAndView("consultant/consultant_tuandui_jx", modelMap);
	}

	/**
	 * @Title: 方法名：yydfl
	 * @Description: 功能描述：预约到访率
	 * @author hqD ☺ ^o^
	 * @date 2018年1月22日 上午11:27:24
	 * @param @param
	 *            modelMap
	 * @param @param
	 *            vo
	 * @param @param
	 *            request
	 * @param @return
	 * @param @throws
	 *            Exception
	 * @return ModelAndView 返回类型
	 */
	@RequestMapping(value = "/yydfl")
	public ModelAndView yydfl(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request) throws Exception {
		modelMap = WebExecutor.execute(logger, vo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				List<TgReserve> reserves = new ArrayList<>();

				HashSet<TgReserve> set = new HashSet<>();
				TgUser user = UserUtil.getUserFromCookies();
				String nickName = request.getParameter("username");
				String date = request.getParameter("date");
				// String keyName = request.getParameter("keyName");
				// if(MathUtil.isEmpty(keyName))
				// keyName = Constants.CENTER_KEYNAME;
				if (MathUtil.isEmpty(date))
					date = format.format(new Date());
				// 获取所有的老师
				if (MathUtil.isEmpty(nickName)) {
					TgUserinfo userinfo = new TgUserinfo();
					List<TgOffice> office = tgOfficeDao.findAll(TgOffice.class);
					for (TgOffice ofo : office) {
						List<TgReserve> reserves_center = new ArrayList<>();
						List<TgUserinfo> users = userinfoDao.get_AllTeachers_ByCenter(ofo.getKeyname());
						for (TgUserinfo user_ : users) {
							if (!"system".equals(user_.getUsername()) && !"system".equals(user_.getNickname())) {
								TgReserve reserve = new TgReserve();
								reserve.setYydfl(reserveDao.getYydfl(user_.getUsername(), date));
								reserve.setQrdfl(reserveDao.getQrdfl(user_.getUsername(), date));
								reserve.setNickname(user_.getNickname());
								reserves_center.add(reserve);
							}
						}
						reserves.addAll(reserves_center);
					}
				} else {
					TgUserinfo userInfo = userinfoDao.getTeacherByNickName(nickName);
					if (MathUtil.isNotEmpty(userInfo)) {
						TgReserve reserve = new TgReserve();
						reserve.setYydfl(reserveDao.getYydfl(userInfo.getUsername(), date));
						reserve.setQrdfl(reserveDao.getQrdfl(userInfo.getUsername(), date));
						reserve.setNickname(userInfo.getNickname());

						reserves.add(reserve);
						result.setDefaultModel("username", nickName);
					}
				}
				// 获取所有的中心
				result.setDefaultModel("office_List", tgOfficeDao.findAll(TgOffice.class));
				result.setDefaultModel("reserves", reserves);
				// result.setDefaultModel("keyName", keyName);
				result.setDefaultModel("date", date);

				return result;
			}
		});
		return new ModelAndView("consultant/yydfl", modelMap);
	}

}
